Create your own memes in Terminal

efdev

Eric F 🇺🇦

Posted on February 19, 2023

Create your own memes in Terminal

To create a “meme”, or just adding text to an image - you don't need an app or an online service. You can do it yourself, in Terminal, using ImageMagick. Here's a short snippet you can use.

Since the command is kind of long, you can save in some file, or make a bash function - or maybe a script.

# ImageMagick v6
$ convert in.jpg -gravity south -font Impact -pointsize 120 -fill white -stroke black -strokewidth 3 -annotate +0+0 'Add text here' out.jpg

# ImageMagick v7
$ magick in.jpg -gravity south -font Impact -pointsize 120 -fill white -stroke black -strokewidth 3 -annotate +0+0 'Add text here' out.jpg
Enter fullscreen mode Exit fullscreen mode

 

Text position

For -gravity you can use your normal: north, south, center, southeast, etc.

 

Fonts

I used Impact in the example. It's usally installed. But, if you want to change the font - just use another one from the list of fonts. Most font names are formatted with a dash, like “DevaVu-Sans-Bold”, “NimbusSans-Bold”, etc.

If you try one and it returns an error - you can get the list of fonts (ie. the font names) using:

# ImageMagick v6
$ identify -list font

# ImageMagick v7
$ magick -list font
Enter fullscreen mode Exit fullscreen mode

To get a more readable list, you can use:

$ identify -list font | grep 'Font'
Enter fullscreen mode Exit fullscreen mode

 

Text stroke

The size of the text stroke depends a little on the font, and what you like. 1-3 are good values. I usually go with 2, and sometimes (depending on the font) I use 1 or 3.

3 is probably closest to what you get at an online meme generator.

 

Example

Here's an example adding text 2 times (top and bottom).

$ magick in.jpg \
  -gravity north -font Impact \
  -pointsize 120 -fill white  \
  -stroke black -strokewidth 3 \
  -annotate +0+0 'Text at top' \
  out1.jpg
$ magick out1.jpg \
  -gravity south -font Impact \
  -pointsize 120 -fill white \
  -stroke black -strokewidth 3 \
  -annotate +0+0 'Text at bottom' \
  out2.jpg
Enter fullscreen mode Exit fullscreen mode

out2.jpg


It's more fun to spend time in Terminal, than at some online meme generator page. Plus, if you dig deeper into ImageMagick - you can add a lot of other effects as well. This was just a simple example.

 

// Happy hacking… 👍

· Eric

💖 💪 🙅 🚩
efdev
Eric F 🇺🇦

Posted on February 19, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Create your own memes in Terminal
imagemagick Create your own memes in Terminal

February 19, 2023