Page 1 of 1

Batch processing using php exec find and xargs

Posted: 2012-08-09T02:15:26-07:00
by peterminten89
Using php, exec and ImageMagick, I am trying to create thumbnails of files scattered over several subdirs. The final goal is, by using php and ImageMagick”, to recursively go through all directories and do the following:
-find all images of the following format xxxxx.jpg where x is a digit
-create in that particular directory a thumbnail version 30x30 with name t_xxxxx.jpg
Reading the different suggestions on this site I created the following lines of php code:
//the following line simply outputs the different files (with complete pathname) in the different directories
$command= “find dirtobeprocessed -type f -regex '.*[1]/[0-9]*\.jpg' | xargs -I FILE echo FILE”; exec($command);

//the following does not work since FILE is the filename with full path
$command= “find dirtobeprocessed -type f -regex '.*[1]/[0-9]*\.jpg' | xargs -I FILE /usr/bin/convert FILE -resize 300x300 t_FILE.jpg”; exec($command);

//so I need to figure out a way to get in the shell command a grip on the path and the filename and then recompose them into the destination filename but here I get stuck; the following eg does not show the filename
$command= “find $dirtobeprocessed -type f -regex '.*[1]/[0-9]*\.jpg' | xargs -I FILE echo ${FILE##*/}”; exec($command);

Any suggestions are more than welcome!

Re: Batch processing using php exec find and xargs

Posted: 2012-08-09T20:04:48-07:00
by anthony
See the notes for draw command quotes -- it has the same problems quotes in quotes...
To Quote or Backslash?
http://www.imagemagick.org/Usage/draw/#quote