Page 1 of 1

Need help to convert Unix Shell Script to DOS Batch Script

Posted: 19 Jul 2015 07:39
by pstein
I have got a little Unix Shell Script for a freeare program called ImageMagick.
There is also a ImageMagick version for Windows and I want to implement a certain task by using a corresponding DOS batch script.

The Unix Shell Script lok like:

Code: Select all

test=`convert image.jpg -format "%[fx:(w/h>1)?1:0]" info:`
if [ $test -eq 1 ]; then
convert image.jpg -resize 800x result
else
convert image.jpg -resize x800 result
fi


How does the DOS batch script look like?

Mind the backticks which tell the shell script interpreter to execute everything inside and assign the result to the variable "test"

Furthermore I am asking how to mask the% percentage inside the parametr list

Maybe someone can help

Thank you
Peter

Re: Need help to convert Unix Shell Script to DOS Batch Scri

Posted: 19 Jul 2015 08:14
by Compo
it may be easier to break the width and height into separate variables first:

Code: Select all

FOR /F %%A IN ('identify -format "Width=%%w\nHeight=%%h" %1') DO SET %%A
IF %Width% GTR %Height% (convert ...) ELSE (convert ...)
Where %1 is obviously the image file as a parameter.

Also I was under the impression that you can set the maximum width or height maintaining aspect ratio with a single command. If that is the case then the following should be sufficient.

Code: Select all

convert -resize 800x800 %1

Re: Need help to convert Unix Shell Script to DOS Batch Scri

Posted: 20 Jul 2015 06:46
by pstein
This works great
Thank you

Re: Need help to convert Unix Shell Script to DOS Batch Scri

Posted: 20 Jul 2015 07:43
by Compo
Out of interest did you try the latter command?

As I stated, it is my understanding from a quick search session that an image would be resized maintaining aspect ratio until the larger axis reaches 800 pixels. Confirmation of my understanding would be appreciated.

Re: Need help to convert Unix Shell Script to DOS Batch Scri

Posted: 20 Jul 2015 08:02
by pstein
confirmed