LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Blogs > dr_agon
User Name
Password

Notices


Rate this Entry

batch resize images using find, xargs and convert

Posted 02-20-2011 at 04:30 PM by dr_agon

applies to: linux, find, xargs, convert, image processing

'convert' command, which is a part of ImageMagick package can be used for image resizing, but it lacks ability to process multiple files (in version of ImageMagick 6.5.7-8 2010-12-02). Instead of writing a shell script you can use find and xargs commands to collect filenames and invoke convert with one filename at a time, like this:

Code:
find -iname "*.jpg" -printf "%f\0" \
 | xargs -0 -I {} convert -resize 50% {} small/{}
The general form would be:
Code:
find [directory to search, if omitted = current] -iname [search pattern] -printf "%f\0" \
 | xargs -0 -I {} convert -resize [% or widthxheight] [directory for converted images]/{}
Little explanation:
The find parameters make search case-insensitive and output NULL delimited filenames without path. The xargs -I {} parameter makes {} a "placeholder" for data from find.
See man pages for details.
Posted in Uncategorized
Views 8185 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 11:33 AM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration