Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm after an osx program that will convert an image into a base64 string (for web development).

Basically replicates this:

I suspect there is no application, and in that case I'd be interested if I can get the terminal command which will encode, to apply to a certain file on Right-Click

Followup question: Can I give Automator apps a window?


I combined the two solutions below, to create an application with the following code

for f in "$@"
    openssl base64 -in "$f" | pbcopy

And infact I made a dropzone target using Platypus, as shown in my subsequent SO question/answer

share|improve this question
up vote 5 down vote accepted

Base64 Automator Droplet

You can use Automator to create your own Base64 droplet. Mac OS X includes openssl which can encode files to Base64; this superuser question explains how, OS X: Base64 encode via command line

  1. Launch
  2. Create a new application
  3. Add a Run Shell Script action
  4. Set Pass input: to as arguments
  5. Within the script, replace echo with the script below.
  6. Save your workflow as an application

To use your application, drag and drop files onto it. A new base64 encoded file will appear next to the original file.

Shell Script

for f in "$@"
    openssl base64 -in "$f" -out "$f.b64"

Automator Base64 droplet

To learn more about using Automator, see Apple's Mac Basics: Automator.

share|improve this answer

One of your possibilites is :

  • Create an Automator service
  • At the top select : Service receives selected image files in Finder
  • Add a Shell Script action
  • Put the following script in it
    • openssl base64 < "$1" | pbcopy
  • Save the service

Now you can from the contextual menu > Service > yourServiceName of every image in the finder get the base64 encoding copied into your clipboard !

share|improve this answer
Thanks. Hm, first try I couldn't get this to work. I'll have another crack when I get some time. But I did combine the use of pbcopy with another answer! – AshCooman Apr 9 '14 at 16:03

I wrote an Applescript for BBEdit: I only use jpg images for this, but it could be adapted for other images and other editors easily:

-- choose file
set _a to choose file of type "jpg"

-- convert path to posix path
set _b to POSIX path of _a

-- strip newlines and place in clipboard
do shell script "openssl enc -base64 -in " & _b & " | tr -d \"\\n\" | pbcopy"
set myClip to the clipboard

-- set strings with placeholder texts for BBEdit
set _start to "<img alt=\"<# some text #>\" width=\"<# width #>\" height=\"<# height #>\" src=\"data:image/jpg;base64,"
set _end to "\" />"
set _string to _start & myClip & _end

tell application "BBEdit"
    set selection to _string
end tell
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.