Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Imagemagick manipulation with base64 images
# create a new image
$ convert -size 10x10 xc:red sample.jpg
# convert to a base64 string
$ base64 sample.jpg
# output to a file:
$ convert 'inline:data:image/jpeg;base64,[BASE64-DATA]' output.jpg
# or, output to a base64 string:
$ convert 'inline:data:image/jpeg;base64,[BASE64-DATA]' JPG:- | base64
# add more options to change the image as needed
# here, resizing the red square 30x30 at the center of a 40x40 white square
$ convert -resize 30x30 -gravity center -background white -extent 40x40 'inline:data:image/jpeg;base64,[BASE64-DATA]' JPG:- | base64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.