Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4125844
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:55:22+00:00 2026-05-20T23:55:22+00:00

Basically I’m trying to write a clever single line of commands that outputs base64

  • 0

Basically I’m trying to write a clever single line of commands that outputs base64 encoded strings in place of where there used to be a path to an image. So:

background-image: url(path/to/my/image.png);

…would turn into:

background-image: url(data:image/png;base64,ABvR0…+tC==);

I normally turn an image into its base64 encoded string via:

openssl enc -base64 -in path/to/my/image.png

Which outputs the base64… but with newlines in it. This is fixed by piping it through tr like:

openssl enc -base64 -in path/to/my/image.png | tr -d '\n'

which just outputs a long base64 encoded string. By using pbcopy (on Mac OS) that gets sent to the clipboard, like so:

openssl enc -base64 -in path/to/my/image.png | tr -d '\n' | pbcopy

Very nice for ad hoc replacing an occasional image with its base64 representation but what I’d like to do is have this automated for replacing all occurrences of url(path/to/whatever.ext) in a file by their respective base64 strings. Making sure there are only actual paths and no data-uris in there is out of scope here 🙂

I have been trying to replace stuff with sed but I got stuck in its horrible documentation. It’s not too difficult to find the occurences of the url(…) pattern in a css file, but the bit between parenthesis needs to be replaced by the output of the above command and I am clueless if this is at all possible. So, there it is, help or some pointers (do I need to look into awk as well?) would be much appreciated! A ‘you cannot do this without a proper script’ would also do of course 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T23:55:23+00:00Added an answer on May 20, 2026 at 11:55 pm

    With openssl tool

    #!/bin/bash
    
    awk -F'[()]' -v q="'" '
    
    /background-image: url(.*)/ {
      cmd=sprintf("openssl enc -base64 -in %s | tr -d %c\\n%c",$2,q,q)
      cmd | getline b64
      close(cmd)
      $0=$1 "(data:image/png;base64," b64 ");"
    }1' /path/to/css/file
    

    Proof of Concept

    See HERE for a working example


    With base64 tool

    #!/bin/bash
    
    awk -F'[()]' '
    
    /background-image: url(.*)/ {
      cmd=sprintf("base64 -w0 %s",$2)
      cmd | getline b64
      close(cmd)
      $0=$1 "(data:image/png;base64," b64 ");"
    }1' /path/to/css/file
    

    Proof of Concept

    See HERE for a working example

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically I'm trying to accomplish the same thing that mailto:bgates@microsoft.com does in Internet Explorer
basically I'm trying to pass a variable that is defined in a JSON array
Basically I want to be able to call jQuery from FireBug, place code that
Basically I am trying to restart a service from a php web page. Here
Basically, I'm trying to tap into the Soap pipeline in .NET 2.0 - I
Basically I’ve heard that certain conditions will cause .NET to blow past the finally
Basically, what I'm trying to create is a page of div tags, each has
basically i need to write a query for mysql, but i have no experience
Basically I have written a game plugin that will allow server admins to update
Basically i have a query string that when i hardcode in the catalogue value

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.