"drag n drop" application to convert images to base64 string (for web development)
I'm after an osx program that will convert an image into a base64 string (for web development).
Basically replicates this: http://webcodertools.com/imagetobase64converter/Create
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?
SOLUTION
I combined the two solutions below, to create an application with the following code
for f in "$@"
do
openssl base64 -in "$f" | pbcopy
done
And infact I made a dropzone target using Platypus, as shown in my subsequent SO question/answer
Solution 1:
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
- Launch Automator.app
- Create a new application
- Add a Run Shell Script action
- Set Pass input: to as arguments
- Within the script, replace
echo
with the script below. - 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 "$@"
do
openssl base64 -in "$f" -out "$f.b64"
done
To learn more about using Automator, see Apple's Mac Basics: Automator.
Solution 2:
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 !