Very often you see images with a quote added to it, sometimes funny, sometimes informational. Adding solid font to an image is quite easy but I didn’t know how to add outlined font (font with a border) to an image. Example of outlined font can be seen in the image below – Original image on the left, quoted image on the right.
Such things are easily done in Photoshop and on Gimp if you’re on Linux. However, being a fan of the command line, I always try to find an alternative solution which doesn’t involve the usage of a GUI based application. After some research, I figured out how to do it with Imagemagick.
It is a two step process – First create the transparent image with the text that you wish to super-impose on the image, and then use the
composite command to merge this image created in the first step with the original image.
For the first step:
convert -background transparent -channel RGBA -gaussian 0x1 -fill white -stroke black -strokewidth 1 -font /home/pratik/.fonts/Unkempt/Unkempt-Bold.ttf -size 720x -pointsize 63 -gravity center -interline-spacing 8 label:"Smriti Irani on being told\n that someone got arrested\n for a fake degree." empty.png
To create the outline effect, we set the
-fill option to
white and then we create a border for the font using the
-stroke option which is set to
-strokewidth controls the width of the border. This lets us create alphabets with a black border and white solid colour within.
label as opposed to
-annotate option of imagemagick lets you add newline characters within the text as you can see above. The
-size option is used to set the width of the textual image that we want to create. It should be typically set to the width of the original image which can be determined using the
identify command. The
-gaussian option is used to give a slight blurred effect to the text. You can use any font you wish to, I’m using the
Unkempt font available on the Google Font Repository.
The next step is to merge the above image with the original image (below).
We will use the
composite command which also comes as part of the imagemagick suite for this purpose.
composite -gravity center outlined-text-image.png smriti-gun.jpg smriti-outlined.jpg
The desired result can be seen below:
man convert is your goto friend to understand what are the various options used in the first command to create the outlined text image.
Do leave a comment if there any questions or suggestions.