Skip to content

Instantly share code, notes, and snippets.

@MikeNGarrett
Created March 26, 2014 00:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save MikeNGarrett/9774888 to your computer and use it in GitHub Desktop.
Save MikeNGarrett/9774888 to your computer and use it in GitHub Desktop.
Imagemagick recursively reduce files to < 800x600 and 72ppi
# This is a bash script meant to be run on the command line. Requires imagemagick (apt-get install imagemagick)
## THIS WILL OVERWRITE YOUR FILES, uses sudo and may not require it.
for file in /path/to/files/*/*.jpg; do sudo convert $file -resize '800x600>' -density 72 $file; done
### another method using resolution (800*600)
for file in /path/to/files/*/*.jpg; do sudo convert $file -resize '480000@>' -density 72 $file; done
### example of *not* overwriting files
for file in /path/to/files/*/*.jpg; do sudo convert $file -resize '800x600>' -density 72 converted-$file; done
@WillHall
Copy link

ty

@asvdw
Copy link

asvdw commented Jun 4, 2016

thank you.
I had to improve it if you have spaces in filename (sometimes users do things like that...)
also add quality param

for file in /path/to/files//.jpg; do sudo convert "$file" -resize '800x600>' -density 72 -quality 85 "$file"; done

@Fayozjon
Copy link

how to change resolution by biggest size for example maximum width 1000 px ?

@MikeNGarrett
Copy link
Author

@Fayozjon you would use the image geometry properties to specify the width only.
convert $file -resize '1000'
I don't think you can specify the > to resize only images larger than the specified dimensions, so be careful with this.

Ready more about Image Geometry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment