Newbie Batch Processing Question

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?".
OldBoy
Posts: 8
Joined: 2011-01-11T14:13:36-07:00
Authentication code: 8675308
Location: Oxfordshire, UK

Re: Newbie Batch Processing Question

Post by OldBoy »

Hi Bonzo and fmw42 - thanks for your time

Bonzo: I tried the code - The only response I got was '%%f was unexpected at this time." :(

fmw42: The version I am using is 6.6.7 Q16, which is the latest version (if I understand it right)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Newbie Batch Processing Question

Post by fmw42 »

Bonzo will have to help further as I know little about windows and IM under windows and windows bat file programming. I use Mac OSX with unix bash shell programming. Sorry.
Last edited by fmw42 on 2011-01-12T12:53:37-07:00, edited 1 time in total.
OldBoy
Posts: 8
Joined: 2011-01-11T14:13:36-07:00
Authentication code: 8675308
Location: Oxfordshire, UK

Re: Newbie Batch Processing Question

Post by OldBoy »

fmw42 wrote:Bonzo will have to help further as I know little about windows and IM under windows and windows bat file programming. I use Max OSX with unix bash shell programming. Sorry.
Thanks anyway fmw42 :D
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Newbie Batch Processing Question

Post by Bonzo »

AH ha I had that error when I was not thinking - you pasted the convert comand into the command prompt box.

You need to save my code example as a bat file somewhere; I put it in the my user folder Anthony.

The images were in a folder called crop_test on my desktop and so the comand to run that is:
C:\Users\Anthony\crop.bat C:\Users\Anthony\Desktop\crop_test C:\Users\Anthony\Desktop\crop_test

First part is the path to the batch script: C:\Users\Anthony\crop.bat
The second is the path to the folder with the images to process: C:\Users\Anthony\Desktop\crop_test
The third is the path to save the images to: C:\Users\Anthony\Desktop\crop_test

Do not forget to cd\ back to the c prompt in the comand window before running the command.

For testing I just created a tempory folder and copied a couple of photos into it and saved the cropped images back to the same folder.
OldBoy
Posts: 8
Joined: 2011-01-11T14:13:36-07:00
Authentication code: 8675308
Location: Oxfordshire, UK

Re: Newbie Batch Processing Question

Post by OldBoy »

Bonzo wrote:AH ha I had that error when I was not thinking - you pasted the convert comand into the command prompt box.

You need to save my code example as a bat file somewhere; I put it in the my user folder Anthony.

The images were in a folder called crop_test on my desktop and so the comand to run that is:
C:\Users\Anthony\crop.bat C:\Users\Anthony\Desktop\crop_test C:\Users\Anthony\Desktop\crop_test

First part is the path to the batch script: C:\Users\Anthony\crop.bat
The second is the path to the folder with the images to process: C:\Users\Anthony\Desktop\crop_test
The third is the path to save the images to: C:\Users\Anthony\Desktop\crop_test

Do not forget to cd\ back to the c prompt in the comand window before running the command.

For testing I just created a tempory folder and copied a couple of photos into it and saved the cropped images back to the same folder.
Thanks Bonzo!!! :D
haleg
Posts: 8
Joined: 2011-01-19T16:54:29-07:00
Authentication code: 8675308

Re: Newbie Batch Processing Question

Post by haleg »

Did you ever get it working? I have been working in DOS batch for a bit, the FOR command is quite particular in its processing particularly with environment variables %1, %2 in a batch file. Give a response back, and I will be checking.
FYI, I tried your command, and you don't seem to need the %d on the output file name. IM CONVERT adds the number automatically.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Newbie Batch Processing Question

Post by Bonzo »

Thanks for the info about the filename and %d
haleg
Posts: 8
Joined: 2011-01-19T16:54:29-07:00
Authentication code: 8675308

Re: Newbie Batch Processing Question

Post by haleg »

The double-quotes in the output are good, and I would suggest putting the input directory (%1) in quotes also.

for %%f in ("%1\*.png") do ( convert "%%f" -crop 128x128 +repage "%2\%%~nf.png" )
[quotes added to input-control][removed '_%%d' as it is not needed]

With this you should be able to have any input directory or output directory, spaces or not.
tg3793
Posts: 6
Joined: 2010-11-19T08:00:56-07:00
Authentication code: 8675308

Re: Newbie Batch Processing Question

Post by tg3793 »

You would use the "mogrify" command instead. That would keep the file name exactly the same:
http://www.imagemagick.org/www/mogrify.html
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Newbie Batch Processing Question

Post by anthony »

OldBoy wrote:Well, it looks like it isn't a quad cut that I need, just equally sized divisions.
for equal sized divisions try the newer
Cropping into roughly Equally Sized Divisions
http://www.imagemagick.org/Usage/crop/#crop_equal

Specifically -crop 2x2@

If the image is an odd size, it will make the left/top images one pixel larger. It only ever generates a 1 pixel size for any number divisions.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply