Machine-generated memes in Perl

Motivation: Annoying People

As a demo, I used a sequence I shot during another vacation from my hotel room on the beach boardwalk at Venice Beach near Los Angeles [5]. It shows a tourist desperately trying to tow back a stubborn Segway to the rental company. Schadenfreude is the only true joy, says the cynic.

After extracting the photos from the video as described earlier, Listing 3 converts the individual frames into an animated GIF movie using the Imager module:

Listing 3



anigif shot*.png

The for loop in line 7 iterates over all file names passed in at the command line. The animation size of 300x200 pixels in lines 14 and 15 and the 26 total frames selected result in an animated GIF of about 1MB named anim.gif.

The write_multi() method writes the frames read previously with the new() function to the hard drive as a .gif file. The necessary image format conversions are done automatically behind the scenes. The make_colors option uses mediancut to normalize the color table between the frames, thereby ensuring faster conversion. It is important to set the gif_loop option to  , causing the browser to run the image sequence forever after loading the image (Figure  5).

Figure 5: The GIF now runs in a browser in an endless loop.

For a perfect finishing touch, I want to add a funny header to all the screenshots, while leaving the footer empty. The script in Listing 1 will do just fine for the single frames:

for i in *.png
  meme-simple $i "SEGWAY FAIL" ""

The command anigif shot*-meme.png reads all files with the -meme.png extension and generates the animated GIF. Figure 6 shows a scene from the masterpiece. Throughout the entire movie, the heading with the title stays motionless and perched 100 pixels below the top edge of the (originally sized) image because the string is built into every frame in the same way. It is white and uses the Impact joke font. If you like, you can check out the animated image online  [6].

Figure 6: The animated GIF contains a header in Impact font in each frame.


At the cutting table, I muse about Internet humor and other design options: Should I perhaps generate jokes automatically from random text? Maybe using quotes from the IMDB movie portal? My interns will be really surprised next summer.


  1. Image Macros:
  2. "I Can Has Cheezburger?":
  3. Listings for this article:
  4. "Battle Over 'GIF' Pronunciation Erupts" by Amy O'Leary, New York Times:
  5. Michael Schilli, "Segway FAIL" (Video):
  6. Animated GIF for "Segway FAIL" movie:

The Author

Mike Schilli works as a software engineer with Yahoo! in Sunnyvale, California. He can be contacted at Mike's homepage can be found at

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • CLI Image Processing

    Powerful command-line tools offer fast and easy image editing.

  • ODF Compatibility

    What happens when you feed an ODT document created with OpenOffice to a word processor like AbiWord, KWord, or Writely? Read on to find out.

  • Perl: Skydiving Simulation

    Computer game programmers apply physical formulas and special tricks to create realistic animations. Simple DirectMedia Layer (SDL), which is available as a Perl wrapper, provides a powerful framework for creating simple 2D worlds with just a couple of lines of code.

  • Custom Publishing

    With LibreOffice Writer and Calibre, you can publish your own ebooks with better results than most online conversion tools.

  • Perl: OpenOffice Label Merge

    OpenOffice offers a selection of preconfigured formats for users who need to print their own self-adhesive labels. Perl feeds the address data to the document.

comments powered by Disqus

Direct Download

Read full article as PDF:

Price $2.95

Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Find SysAdmin Jobs