Batch image resizing with Imagemagick

Automate resizing images on Linux

This tutorial shows you how to list your images in a csv file and resize every image in that list automatically.


ImageMagick is a free and open-source software suite for displaying, converting, and editing raster image and vector image files. 

Prepare the scripts

  • Log in your Linux system
  • Run the following command in your bash console to list every JPG in the specified folder recursively and save it into a csv file
find /home/project/ -name "*.jpg" -print| while read LINE; do echo "$LINE" ; done > list_with_images.csv
  • Create a file named “”
# define the settings

end=$(cat $1 | wc -l)
# loop through every line of the given file
while read file; do
    echo "[x] Optimizing $file"
    echo $(($end-$((++start)))) elements remaining of $end
    echo "Optimizing $file to $targetFile"
    convert "$file" -resize 1920 "$targetFile"
    # let the CPU rest for 10 sec
    sleep 10
done < $1

You can edit the script to your liking. it doesn’t replace the original image, but creates a new one with a postfix of “_optimized”.
Original: test_image.jpg
Optimized: test_image_optimized.jpg

Run the script

sh list_with_images.csv

Learn more about Linux bash tricks

Add SSH key to authorized_keys

Add SSH key to authorized_keys

It has been always a pain to put your server’s password every damn time. You can add your key to the authorized_keys of the server. Here’s how you do it

Generate your SSH key if you don’t have one already.

ssh-keygen -t rsa -b 2048

Copy your generated SSH key to the server
Insert the password of your server when prompted

ssh-copy-id [email protected]

Connect to the server without a password πŸ”₯

ssh [email protected]