0

I have a folder of HD images, +2000px width :

+ /img/
   +- /bikes/: few images here (jpg,png,svg)
   +- /cars/ : few images here
   +- /cats/ : few images here
   +- /dogs/ : few images here
   +- /...

I would like to bach resize the whole into 200px width images (same ratios) yet keep the folder structure.

How to do so ?

Hugolpz
  • 17,296
  • 26
  • 100
  • 187
  • A Google search for `imagemagick resize recursive` seems to yield good results – Pekka Feb 03 '16 at 15:21
  • 1
    http://stackoverflow.com/questions/10802606/how-to-batch-resize-images-in-ubuntu-recursively-within-the-terminal I think the size argument for resizing images to 200 px width is `-resize 200x` – Pekka Feb 03 '16 at 15:22
  • Do you mean to overwrite the original images, or create new, smaller files with new names? – Mark Setchell Feb 03 '16 at 15:28
  • @MarkSetchell: I mean to create new ones, either in same folder with a `-small` or in a parallel folder-tree. – Hugolpz Feb 03 '16 at 16:04

1 Answers1

2

You can do something like this, but please make a backup first!

find . -depth -type d \! -name '.' -exec bash -c 'cd $0 || exit; mkdir thumbs 2> /dev/null; shopt -s nullglob; mogrify -path thumbs -resize 200x *.jpg *.svg *.png ' {} \;

which will get you a subdirectory called thumbs in each directory with the smaller versions in there

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • It works. There was a bug with svg files that I bypassed by adding `-format png`, my command is now : `find . -depth -type d \! -name '.' -exec bash -c 'cd $0 || exit; mkdir thumbs 2> /dev/null; shopt -s nullglob; mogrify -path thumbs -resize 128x -format png *.jpg *.svg *.png *.tif' {} \; ` – Hugolpz Feb 14 '16 at 13:47