Skip to content

Instantly share code, notes, and snippets.

@bend
Created December 31, 2018 14:54
Show Gist options
  • Save bend/7dd8cf42f78578ddaaf4f7426cad07b0 to your computer and use it in GitHub Desktop.
Save bend/7dd8cf42f78578ddaaf4f7426cad07b0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Purpose: batch image resizer
# Source: https://guides.wp-bullet.com
# Author: Mike
# absolute path to image folder
FOLDER="/var/www/wp-bullet.com/wp-content/uploads"
# max height
WIDTH=540
# max width
HEIGHT=300
#resize png or jpg to either height or width, keeps proportions using imagemagick
#find ${FOLDER} -iname '*.jpg' -o -iname '*.png' -exec convert \{} -verbose -resize $WIDTHx$HEIGHT\> \{} \;
#resize png to either height or width, keeps proportions using imagemagick
#find ${FOLDER} -iname '*.png' -exec convert \{} -verbose -resize $WIDTHx$HEIGHT\> \{} \;
#resize jpg only to either height or width, keeps proportions using imagemagick
find ${FOLDER} -iname '*.jpg' -exec convert \{} -verbose -resize $WIDTHx$HEIGHT\> \{} \;
# alternative
#mogrify -path ${FOLDER} -resize ${WIDTH}x${HEIGHT}% *.png -verbose
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment