WatchDirectory home page
WatchDirectory Startseite (Deutsche Version)
Site WatchDirectory (Français)
  Welcome, Guest. Please Login or Register
YaBB - Yet another Bulletin Board
   
  HomeHelpSearchLoginRegister  
 
Page Index Toggle Pages: 1
WatchDir ImageMagick and Dos batch question (Read 5738 times)
cbonallo
YaBB Newbies
*
Offline



Posts: 5
WatchDir ImageMagick and Dos batch question
Aug 20th, 2011 at 1:37am
 
I am so close to getting this but I cannot get the right syntax.  I have been using Witchdir to monitor a directory and then use imagemagick to batch resize the images to a new folder.  This has been working great.  Now I've been thrown a curve ball because they wat to just square up the image to the greater of the height or width.  I cannot seem to assign the variable the width and height from the image file:

FOR %%x IN ("C:\Program Files\ImageMagick-6.5.6-Q8\identify.exe" -ping -format "%%w" "%WD_FILE%") DO SET IMGWIDTH=%%x
FOR %%y IN ("C:\Program Files\ImageMagick-6.5.6-Q8\identify.exe" -ping -format "%%h" "%WD_FILE%") DO SET IMGHEIGHT=%%y

This sets the variable first to
"C:\Program Files\ImageMagick-6.5.6-Q8\identify.exe"
then -ping
then -format
then  "%%w"
then "%WD_FILE%"

So it's breaking up my imagemagick command rather than running it and assigning the width or height to the variable. 

Anyone know how to fix this?
Back to top
 
 
IP Logged
 
cbonallo
YaBB Newbies
*
Offline



Posts: 5
Re: WatchDir ImageMagick and Dos batch question
Reply #1 - Aug 20th, 2011 at 1:39am
 
I have tried:

FOR /F %%x IN ("C:\Program Files\ImageMagick-6.5.6-Q8\identify.exe" -ping -format "%%w" "%WD_FILE%") DO SET IMGWIDTH=%%x
FOR /F %%y IN ("C:\Program Files\ImageMagick-6.5.6-Q8\identify.exe" -ping -format "%%h" "%WD_FILE%") DO SET IMGHEIGHT=%%y

and

FOR /F %%x IN ('"C:\Program Files\ImageMagick-6.5.6-Q8\identify.exe" -ping -format "%%w" "%WD_FILE%"') DO SET IMGWIDTH=%%x
FOR /F %%y IN ('"C:\Program Files\ImageMagick-6.5.6-Q8\identify.exe" -ping -format "%%h" "%WD_FILE%"') DO SET IMGHEIGHT=%%y

neither works.
Back to top
 
 
IP Logged
 
Gert
YaBB Administrator
*****
Offline



Posts: 2225
The Netherlands
Re: WatchDir ImageMagick and Dos batch question
Reply #2 - Aug 20th, 2011 at 9:16am
 
I think you should look at the usebackq option, see
for /?
for more help about it.

Your current use of " (quotes) is probably confusing the command processor.
Back to top
 

Gert Rijs - gert (at) gdpsoftware (dot) com
Blog: http://blog-en.gdpsoftware.com/
End Alzheimer's: http://www.alz.org&&...
WWW WWW GdPSoftware  
IP Logged
 
cbonallo
YaBB Newbies
*
Offline



Posts: 5
Re: WatchDir ImageMagick and Dos batch question
Reply #3 - Aug 30th, 2011 at 8:46pm
 
The quotes are necessary for Image Magick or it wont interpret the symbols properly.
Back to top
 
 
IP Logged
 
cbonallo
YaBB Newbies
*
Offline



Posts: 5
Re: WatchDir ImageMagick and Dos batch question
Reply #4 - Aug 30th, 2011 at 8:54pm
 
So would the syntax be this:

FOR /F "usebackq %%x" IN ('"C:\Program Files\ImageMagick-6.5.6-Q8\identify.exe" -ping -format "%%w" "%WD_FILE%"') DO SET IMGWIDTH=%%x
FOR /F "usebackq %%y" IN ('"C:\Program Files\ImageMagick-6.5.6-Q8\identify.exe" -ping -format "%%h" "%WD_FILE%"') DO SET IMGHEIGHT=%%y

Or this using the usebackq:

FOR /F "usebackq %%x IN ('"C:\Program Files\ImageMagick-6.5.6-Q8\identify.exe" -ping -format "%%w" "%WD_FILE%"') DO SET IMGWIDTH=%%x"
FOR /F "usebackq %%y IN ('"C:\Program Files\ImageMagick-6.5.6-Q8\identify.exe" -ping -format "%%h" "%WD_FILE%"') DO SET IMGHEIGHT=%%y"

Thanks so much for your help!
Back to top
 
 
IP Logged
 
Gert
YaBB Administrator
*****
Offline



Posts: 2225
The Netherlands
Re: WatchDir ImageMagick and Dos batch question
Reply #5 - Aug 31st, 2011 at 6:52am
 
I am not sure, you need to experiment a bit with it.

One thing I *AM* sure of is that all those quotes can easily confuse the command processor AND the reader (you and me) of the script. Perhaps you should rewrite the script a bit and use a temporary file.

Code:
"C:\Program Files\ImageMagick-6.5.6-Q8\identify.exe" -ping -format "%%w" "%WD_FILE%" > "C:\Temp\tempfile_width.txt"
"C:\Program Files\ImageMagick-6.5.6-Q8\identify.exe" -ping -format "%%h" "%WD_FILE%" > "C:\Temp\tempfile_height.txt"
 



And now you can use FOR /F to parse those 2 files. Should be a lot easier without those confusing quotes.
Back to top
 

Gert Rijs - gert (at) gdpsoftware (dot) com
Blog: http://blog-en.gdpsoftware.com/
End Alzheimer's: http://www.alz.org&&...
WWW WWW GdPSoftware  
IP Logged
 
cbonallo
YaBB Newbies
*
Offline



Posts: 5
Re: WatchDir ImageMagick and Dos batch question
Reply #6 - Sep 1st, 2011 at 11:40pm
 
Thanks a bunch! I got it to work with the temp files but I am concerned that with this batch running that the value in the temp files will not be correct if it gets fired off several times rapidly.  Will the temp file also be locked because the previous batch will still be reading from the file?  Any thoughts?

Cory Bonallo
Back to top
 
 
IP Logged
 
Gert
YaBB Administrator
*****
Offline



Posts: 2225
The Netherlands
Re: WatchDir ImageMagick and Dos batch question
Reply #7 - Sep 2nd, 2011 at 9:12am
 
Well, if you use the "run a batch file" task, you can decide if multiple batches run at once.

But you can make the temp file more variable, for example by using the name of the detected file. Something like
Code:
SET TF=C:\Temp\temp_%WD_FILE_B%
"C:\Program Files\ImageMagick-6.5.6-Q8\identify.exe" -ping -format "%%w" "%WD_FILE%" > "%TF%_width.txt"
"C:\Program Files\ImageMagick-6.5.6-Q8\identify.exe" -ping -format "%%h" "%WD_FILE%" > "%TF%_height.txt"
  



Make sure to remove the temp files when you are done.
Back to top
 

Gert Rijs - gert (at) gdpsoftware (dot) com
Blog: http://blog-en.gdpsoftware.com/
End Alzheimer's: http://www.alz.org&&...
WWW WWW GdPSoftware  
IP Logged
 
Page Index Toggle Pages: 1