19

I have huge, 12GB, gallery on the server, full of images in various subfolders. Those files are too big and not used in full resolution. I need to resize all the images down to 820px wide (keeping proportions). So my question is - how can I create some kind of crawling script which would resize all images bigger then 820px and save them back overwriting original file?

Hope you can help me :-) Thank you in advance.

G-Gore
  • 191
  • 1
  • 1
  • 3
  • 3
    `find . -name "*.jpg" -exec mogrify -resize 820x {} +` will do them all; if you don't want to process the "less than 820px" ones, there are some options [here](http://unix.stackexchange.com/q/38943). – don_crissti Apr 15 '15 at 14:00

1 Answers1

24

ImageMagick tools convert or mogrify will do the job.

You can get them via your package manager or the source/rpms here.

Basic usage (will overwrite the original file):

$ mogrify -resize 820x ./*.jpg

If you need recursion:

find . -name '*.jpg' -execdir mogrify -resize 820x {} +
Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501
  • 1
    I don't think that "820px wide (keeping proportions)" means "resizing to 820x820". It's rather more like "820px wide and whatever-the-proportion-is high" ;) Plus this does not handle recursiveness. – Erathiel Apr 15 '15 at 15:42
  • 1
    Good point. Edited! –  Apr 15 '15 at 19:22
  • 2
    If you want to make it so that it only resizes if they are larger than set dimensions and still keep the ratios, you can change it to this: `find . -name '*.jpg' -execdir mogrify -resize '820x620>' {} \;` – OpensaurusRex Dec 08 '18 at 22:30
  • 5
    Caution: This will overwrite your existing images. – admin Aug 09 '19 at 21:31
  • Related: [How do I control the compression rate of mogrify?](https://superuser.com/q/79287/358758) (Super User) – Marc.2377 Nov 29 '19 at 19:37
  • Where's the `convert` example? – chovy May 16 '22 at 05:38
  • To only resize larger files, you can do `find . -size +200k -execdir ...` (only resize bigger than 200 kb+) – SurpriseDog Mar 10 '23 at 21:36