Batch image resizing with Imagemagick

Words
230
Reading
2 min
Listen
Play
7y


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


Imagemagick

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 "resize_with_imagemagic.sh"
# define the settings
export MAGICK_THREAD_LIMIT=1;
export MAGICK_THROTTLE_LIMIT=100;
export MAGICK_MEMORY_LIMIT=500mb;

start=0;
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
replace="_optimized.jpg"
targetFile="${file/.jpg/_optimized.jpg}"
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 resize_with_imagemagic.sh list_with_images.csv

Learn more about Linux bash tricks

amzn_assoc_tracking_id = "pawiromitchel-20"; amzn_assoc_ad_mode = "manual"; amzn_assoc_ad_type = "smart"; amzn_assoc_marketplace = "amazon"; amzn_assoc_region = "US"; amzn_assoc_design = "enhanced_links"; amzn_assoc_asins = "B00JRGCFLA"; amzn_assoc_placement = "adunit"; amzn_assoc_linkid = "f4896846b6de16f7bff62fd9e1a58217";

Posted from my blog with SteemPress : http://mpawirodinomo.abovenormal.co/2019/05/batch-image-resizing-with-imagemagick/
Batch image resizing with Imagemagick | Ecency