How to make thumbnail images in Linux
In this article we will use imagemagick which can be used in almost all operating systems, nonetheless, we will use Ubuntu (similarly any Debian-based OS) to write our Terminal command.
First of all, please make sure it is installed on your system.
In Debian distributions you can easily install it with the following command:
sudo apt install imagemagicNow we need to write a script to iterate our existing directories which contain our target images to make thumbnails of.
Here’s what it might look like:
for f in $(find . -name '*.jpg' -or -name '*.jpeg' -or -name '*.JPEG' -or -name '*.JPG' -or -name '*.png' -or -name '*.PNG' -or -name '*.gif' -or -name '*.GIF');doecho $f; done
This command iterates through all directories and subdirectories nesting in the current directory and finds all matching image formats (JPEG, JPG, jpg, png, PNG,…) then echos their path and name.
Get Yousef Fatouraee’s stories in your inbox
Join Medium for free to get updates from this writer.
Now that we have written the loop, we are ready to convert images using the convert command.
Ultimately, simply write:
for f in $(find . -name '*.jpg' -or -name '*.jpeg' -or -name '*.JPEG' -or -name '*.JPG' -or -name '*.png' -or -name '*.PNG' -or -name '*.gif' -or -name '*.GIF');do mkdir -p $(dirname $f)"/thumb150x150";
convert $f -thumbnail 150x150 $(dirname $f)"/thumb150x150/"$(basename $f);: 'to add more sizes, repeat the last two lines above and change their attributes here...'done
Notes:
- Do not run it more than once, It is always better to test its functionality first.
- This command makes thumb150x150 (or any given name) directory alongside any finding image and makes thumbnails with the same name as original files inside the new folder.
example result:
Original image:
./path/to/image/genuine.jpg
Converted thumbnail:
./path/to/image/thumb150x150/genuine.jpg - To change the thumbnail size you can easily change the dimension numbers of the -thumbnail flag (e.g. 300x300).





