Batch processing using php exec find and xargs

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
peterminten89
Posts: 1
Joined: 2012-08-09T01:58:00-07:00
Authentication code: 67789

Batch processing using php exec find and xargs

Post 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!
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Batch processing using php exec find and xargs

Post 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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply