Featured image of post Create awesome images with ImageMagick

Create awesome images with ImageMagick

Automatically download images from Unsplace and generate text using ImageMagick.

Look into my glass ball

ImageMagick is a free and open-source cross-platform software suite for displaying, creating, converting, modifying, and editing raster images. Created in 1987 by John Cristy, it can read and write over 200 image file formats. It and its components are widely used in open-source applications.

I’ve experimented with a few solutions to create text on images, there is some great application like Paint.Net, Gimp, Canva and even PowerPoint to quickly and easily create great looking images with a text overlay.

My use case was a bit different, when hosting events it is a great marketing tool to have a count down timer image, each day you post an image with the amount of days left to register and attend.. Don’t know if this still works for most folks, but I always love seeing these types of images, let me think of countdown to something important like going to the moon..

At first I use to make use of a image editor to create multiple images, and just change the text value. This worked great, but it takes a lot of time.

I then developed a application that draws on a image, running this on a loop, created a a bunch of images very quickly.

Finally I started playing with ImageMagick and I must say I love it, you can do so much with this great software and it is free. I can now quickly watermark my images, add text to them and also resize them for the different social media channels… I know what you are thinking.. but you could do this anyways using some of the tools that you mentioned..

Powershell for the win!

I’m a avid user of Powershell, I’ve been using it for many years, and for a lot of my tool development needs, I’d rather create a powershell script than a C# application. I just found that Powershell is probably the fastest way to create a script and get going, rather than creating a new project, compiling etc..

I’ve made use of Powershell to download a random image, add the text I want onto the image and save the image with a prefix. This is easier than it sounds, and you can download the script from my GitHub repro.

ImageMagick pulling a rabbit out of the hat.

ImageMagick uses command line syntax to create, convert, append or resize images. An example to will be :

magick convert -background '#0008' -fill white -font 'Chiller' -gravity center -size 1024 -pointsize 100 caption:"20 Days left! \n Visit aka.ms/ctppug to register" image1.jpg +swap -gravity center -composite image2.jpg

Another example

magick convert "wizzard1.jpg" -stroke black -strokewidth 3  -background '#f3f6f4' -fill "rgba(0,134,191,0.3)" -font 'Chiller' -size 1280x1600 -pointsize 100 -draw "rectangle 0,800 1600 950"  -annotate +20+900 "Create Images with ImageMagick"  -append image_wizzard.jpg

This command will use image1.jpg and add text “20 Days Left!” using the fonts Chiller onto the image, it will then save it as image2.jpg.

Multiple Lines
There is multiple ways to create multiline text, but the easiest is to make use of **'\n'** as a line break.

For my next trick

Now I know what you might be thinking, I want to see the script, and I’ll take you step by step through my solution.

Buy me a coffee

If you like this content why not buy me a coffee? Buy Me A Coffee

Built with Hugo
Theme Stack designed by Jimmy