Page 1 of 1

Help with translating bash script for Windows

Posted: 2017-11-04T04:05:39-07:00
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 :)

Re: Help with translating bash script for Windows

Posted: 2017-11-04T07:47:33-07:00
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.

Re: Help with translating bash script for Windows

Posted: 2017-11-04T08:39:21-07:00
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
)

Re: Help with translating bash script for Windows

Posted: 2017-11-04T17:27:25-07:00
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