Need help to convert Unix Shell Script to DOS Batch Script

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
pstein
Posts: 125
Joined: 09 Nov 2011 01:42

Need help to convert Unix Shell Script to DOS Batch Script

#1 Post by pstein » 19 Jul 2015 07:39

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

Compo
Posts: 600
Joined: 21 Mar 2014 08:50

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

#2 Post by Compo » 19 Jul 2015 08:14

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

pstein
Posts: 125
Joined: 09 Nov 2011 01:42

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

#3 Post by pstein » 20 Jul 2015 06:46

This works great
Thank you

Compo
Posts: 600
Joined: 21 Mar 2014 08:50

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

#4 Post by Compo » 20 Jul 2015 07:43

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.

pstein
Posts: 125
Joined: 09 Nov 2011 01:42

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

#5 Post by pstein » 20 Jul 2015 08:02

confirmed

Post Reply