#Blueserv.net

Creating thumbnails using ImageMagick

Written by Frans on January 27 2019.
Last modified on: February 03 2019 22:20.

What is the purpose of a thumbnail

I'm using thumbnails for the purpose of adding illustrative visuals that go together with the information links.

The definition according to Wikipedia:
"Thumbnails are reduced-size versions of pictures or videos, used to help in recognizing and organizing them, serving the same role for images as a normal text index does for words. In the age of digital images, visual search engines and image-organizing programs normally use thumbnails, as do most modern operating systems or desktop environments, such as Microsoft Windows, macOS, KDE (Linux) and GNOME (Linux)."

See https://en.wikipedia.org/wiki/Thumbnail.

How it's done

A thumbnail can be easily created from an existing image file using the toolchain provided by ImageMagick.

Using convert you can define your input original and scale it within a new thumbnail file.

convert camera-playback.jpeg -thumbnail '240x128' -background white -gravity west -extent 128x128 camera-playback-thumb.jpeg

Parameters have the following purpose:

Example of creating thumbnails from a photo, the historical Hong Kong Star Ferry in front of the famous Hong Kong skyline of Hong Kong Island:

Results into the following thumbnails:

Scaled linearly keeping the image aspect ratio Scaled linearly to thumbnail size scaled linearly to thumbnail size and positioned the image on the right scaled linearly to thumbnail width, cropping the image to fit scaled linearly to thumbnail width, cropping after positioning the image on the bottom side
convert star-ferry-original.jpeg -thumbnail 128x128 -background yellow -gravity center star-ferry-scaled.jpeg
convert star-ferry-original.jpeg -thumbnail 128x128 -background yellow -gravity center -extent 128x128 star-ferry-scaled2.jpeg
convert star-ferry-original.jpeg -thumbnail 128x128 -background yellow -gravity east -extent 128x128 star-ferry-scaled3.jpeg
convert star-ferry-original.jpeg -thumbnail 128x -background yellow -gravity center -extent 128x128 star-ferry-scaled4.jpeg
convert star-ferry-original.jpeg -thumbnail 128x -background yellow -gravity north -extent 128x128 star-ferry-scaled5.jpeg