Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImageMagik/UNIX: How to recursively process a nested directory of photos?

Question: How do I recursively process, using Imagemagik (convert), a nested directory of photos?

I have the following directory structure:

/
..2008/
....a.jpg
....b.jpg
..2009/
.....c.jpg

And I want to run the following ImageMagik command on each file, to clean/resize up the images, and then save the resulting image out as the exact same filename as the original file. Basically, I want to replace the original file with the generated resized file created.

// from unix command line    
convert FILENAME.jpg -resize 100x100 -sharpen 1.5 -strip -profile "*" -sampling-factor 4x1 -quality 80 FILENAME.jpg;
like image 481
TeddyR Avatar asked Dec 06 '25 00:12

TeddyR


1 Answers

Try using find -exec. For instance:

find dirname -type f -iname "*.jpg" -exec convert \{\} -resize 100x100 -sharpen 1.5 -strip -profile "*" -sampling-factor 4x1 -quality 80 \{\} \;

By the way, I don't recommend in-place editing. It's generally a bad idea, especially with storage so cheap. Why not be safe?

like image 57
Borealid Avatar answered Dec 08 '25 05:12

Borealid



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!