Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Create your own memes in Terminal
Eric F 🇺🇦
Eric F 🇺🇦

Posted on

     

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$convertin.jpg-gravity south-font Impact-pointsize 120-fill white-stroke black-strokewidth 3-annotate +0+0'Add text here' out.jpg# ImageMagick v7$magickin.jpg-gravity south-font Impact-pointsize 120-fill white-stroke black-strokewidth 3-annotate +0+0'Add text here' out.jpg
Enter fullscreen modeExit fullscreen mode

 

Text position

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

 

Fonts

I usedImpact 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 modeExit fullscreen mode

To get a more readable list, you can use:

$identify-list font |grep'Font'
Enter fullscreen modeExit 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).

$magickin.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 modeExit 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

Top comments(2)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
chrisgreening profile image
Chris Greening
generalized specialist - software engineer and data scientist - particularly fond of Python and R
  • Email
  • Location
    New York metropolitan area
  • Education
    BSc in Physics, Stony Brook University, New York
  • Work
    Manager of Analytics Engineering at route1.io | Freelance software engineer and data scientist
  • Joined

Lol this is a really fun tutorial, thank you for sharing Eric!

Always love learning new ways to use command line tools, I've had a lot of fun building all sorts of little DIY projects with ImageMagick, FFmpeg, etc

CollapseExpand
 
efdev profile image
Eric F 🇺🇦
Linux & Mac user. Like scripting, open-source, computers/servers in general, and DIY. Doing some web-dev, and the constant rebuild of my home network.Facebook… No way.
  • Location
    Inbetween Europe (mostly Swe)
  • Joined

Thanks Chris! 👍

Yes, you can do a lot of DIY witht those to. I use ffmpeg as well, to create mp3's and m4a's. So much easier when you have them in like a function or script - instead of using a GUI program. :)

/* Beside ImageMagick, to optimize the images - I also use jpegoptim, optipng and gifsicle. They're also really easy to use with scripts/functions. :) */

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Linux & Mac user. Like scripting, open-source, computers/servers in general, and DIY. Doing some web-dev, and the constant rebuild of my home network.Facebook… No way.
  • Location
    Inbetween Europe (mostly Swe)
  • Joined

Trending onDEV CommunityHot

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp