Skip to content

Instantly share code, notes, and snippets.

@frankIT
Last active November 23, 2017 00:54
Show Gist options
  • Save frankIT/faa1a648d8b8b6bcc820 to your computer and use it in GitHub Desktop.
Save frankIT/faa1a648d8b8b6bcc820 to your computer and use it in GitHub Desktop.
batch resize img linux
#!/bin/bash
# it will substitute all source files and needs to work with absolute paths
#for f in *.jpg; # loop folder
for f in $(find "/absolute/path/" -name '*.jpg'); do # loop folder recursively
# crop images to squared ones according to the shorter side of the source
do convert $f -gravity center -crop `identify -format "%[fx:min(w,h)]x%[fx:min(w,h)]+0+0" $f` +repage $f;
# resize the canvas of the source images to squared ones according to the larger side of the source and fill the gaps with a bg color
do convert $f -resize "600x600" -gravity center -background "#f6f6f6" -extent 600x600 $f;
# resize the image to a with of 1080 preserving the aspect ratio
do convert $f -resize 1080 -quality 80 $f;
# resize the image to a height of 1080 preserving the aspect ratio
do convert $f -resize x1080 -quality 80 $f;
# resize the image to a height of 1080 not preserving aspect ratio
do convert $f -resize x1080! -quality 80 $f;
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment