Skip to content

Instantly share code, notes, and snippets.

@schelkanov
Forked from vadimkantorov/image2urijpeg.sh
Created June 16, 2018 00:53
Show Gist options
  • Save schelkanov/95c5d67d3013ceadb0980b46ecb3c05a to your computer and use it in GitHub Desktop.
Save schelkanov/95c5d67d3013ceadb0980b46ecb3c05a to your computer and use it in GitHub Desktop.
Convert an image to Base64 data-uri format using ImageMagick and OpenSSL
# Usage:
# bash image2urijpeg.sh image.jpg 320x240 > base64.txt # will resize before conversion
# bash image2urijpeg.sh image.jpg > base64.txt # will keep original size
magick "$1" -resize ${2:--} jpeg:- | openssl enc -base64 -A | sed -e 's/^/data:image\/jpeg;base64,/'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment