Skip to Content
Linux Multimedia Hacks
book

Linux Multimedia Hacks

by Kyle Rankin
November 2005
Beginner content levelBeginner
330 pages
9h 44m
English
O'Reilly Media, Inc.
Content preview from Linux Multimedia Hacks

Make Image Thumbnails

Use a simple script to create thumbnails from any number of images.

[Hack #2] introduced the convert utility as a means to convert between different image formats and perform basic image processing from the command line. convert also has resizing options that make it perfect for creating image thumbnails.

The primary argument used to create an image thumbnail is -thumbnail. This argument tells convert to create a thumbnail of the input image with the specified geometry. Thumbnails are scaled-down versions of the original, which means the height-to-width ratio is automatically preserved, so you need to specify only one dimension for the conversion. For instance, to create a thumbnail that has a width of 160 pixels, type:

	$ convert -thumbnail 160 image.jpg thumbnail.jpg

To create a thumbnail with a height of 160 pixels, precede the geometry with x:

	$ convert -thumbnail x160 image.jpg thumbnail.jpg

This command comes in particularly handy if you plan to upload a lot of digital photos to a web gallery, because you can script the entire operation. To create a thumbnail with a width of 160 pixels from every JPEG image in a directory, type

	$ for i in *.jpg; do convert -thumbnail 160 $i thumb-$i; done;

Each image in the directory will have a thumbnail with thumb- at the beginning of the filename. This command also works well to create a series of thumbnails of different sizes—just run two different convert commands in the script. So, to create a mid-sized thumbnail with ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

CentOS Bible

CentOS Bible

Christopher Negus, Timothy Boronczyk
Microsoft® SQL Server 2012 Unleashed

Microsoft® SQL Server 2012 Unleashed

Ray Rankins, Paul T. Bertucci, Chris Gallelli, Alex T. Silverstein

Publisher Resources

ISBN: 0596100760Errata Page