Help with translating bash script for Windows

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
jessicaC
Posts: 6
Joined: 2017-11-04T04:03:17-07:00
Authentication code: 1152

Help with translating bash script for Windows

Post by jessicaC »

hi everyone. So I have the below script to generate contact sheets for large image files in bash/Linux. However I need to transfer this to Windows notebook at work (I am not allowed to instull Linux there).
I have installed ImageMagic for Windows

I am just so lost at how to make it all work in either command line or Window's powershell. I am still reading, but it takes time. Perhaps any advanced Windows professionals would help me with translation of the below code for Windows? I would be so very grateful. Thanks so much :)

Code: Select all

IFS=$'\n'
mkdir n;

for f in `find . -iname "*jpg"`; do 


convert $f -set option:mylabel "%wx%h\n%f" -verbose -font Helvetica -pointsize 15 -geometry 200x200+2+2 -auto-orient -resize 200x200 -fill 'gray' -gravity center label:"%[mylabel]" -append n/$f;done

cd n;
montage -font Helvetica -pointsize 10 -background '#FFFFFF' -fill 'gray'  -geometry 300x300+2+2 -auto-orient  * contact-light.jpg
mv contact-light.jpg ../
cd ../
rm n -rf
It would be perfect to just make any executable file and run it in specific folder, just like I have .sh bash scripts with the above code :)
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Help with translating bash script for Windows

Post by GeeMack »

jessicaC wrote: 2017-11-04T04:05:39-07:00I am just so lost at how to make it all work in either command line or Window's powershell. I am still reading, but it takes time. Perhaps any advanced Windows professionals would help me with translation of the below code for Windows? I would be so very grateful. Thanks so much
This simple BAT script should be almost an exact translation from your bash script to Windows CMD...

Code: Select all

@echo off

mkdir n

for %%I in ( *.jpg ) do (
   convert "%%I" -set option:mylabel "%%[w]x%%[h]\n%%[f]" -verbose ^
   -font Helvetica -pointsize 15 -geometry 200x200+2+2 -auto-orient ^
   -resize 200x200 -fill gray -gravity center label:"%%[mylabel]" -append "n\%%I"
)

cd n

montage -font Helvetica -pointsize 10 -background #FFFFFF -fill gray ^
   -geometry 300x300+2+2 -auto-orient *.jpg contact-light.jpg

move contact-light.jpg ..\

cd ..\

rmdir /s /q n

exit /b
Copy that into a text editor and save it with a name like "myscript.bat". If the script is in the same directory as your images, you should be able to run it from a Windows command prompt or by double-clicking it in a Windows explorer (file manager) window.

To run those commands directly from the command line you'd need to change any double percent signs "%%" to singles "%".

I haven't tried working it into a PowerShell script, but it's so simple I probably wouldn't bother.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Help with translating bash script for Windows

Post by snibgo »

The question is really about scripting, not ImageMagick.

See IM with Cygwin and http://www.imagemagick.org/Usage/windows/

If you have many bash scripts, I suggest you install bash on your Windows computer.

Bash and Windows BAT scripts have different "for" commands. So:

Code: Select all

for f in `find . -iname "*jpg"`; do 
convert $f -set option:mylabel "%wx%h\n%f" -verbose -font Helvetica -pointsize 15 -geometry 200x200+2+2 -auto-orient -resize 200x200 -fill 'gray' -gravity center label:"%[mylabel]" -append n/$f ;
done 
... becomes (untested)...

Code: Select all

for %%F in (*jpg) do (
convert %%F -set option:mylabel "%%wx%%h\n%%f" -verbose -font Helvetica -pointsize 15 -geometry 200x200+2+2 -auto-orient -resize 200x200 -fill gray -gravity center label:"%%[mylabel]" -append n\%%F
)
snibgo's IM pages: im.snibgo.com
jessicaC
Posts: 6
Joined: 2017-11-04T04:03:17-07:00
Authentication code: 1152

Re: Help with translating bash script for Windows

Post by jessicaC »

thanks for reply everyone, actually managed to translate everything myself.

About 10 minutes reading on syntax and rules of Windows PowerShell, and I set it all up. Thought it would differ much from bash, but it doesn't.

The topic may be locked/marked SOLVED
Post Reply