Page 1 of 1

bat file for compose .jpg .png with same name

Posted: 2019-03-04T08:59:14-07:00
by ChristianK
Hi all,
I try to compose thousand of images with IM7 on Windows with a script in .bat file :
always have the same file in .jpg and .png format, and have to compose them for each images

I want to do this command :
"C:\Program Files\ImageMagick\magick.exe" *.jpg ( *.png" -negate ) -alpha off -compose copy_opacity -composite

In a folder, have images like this :
- image001.jpg
- image001.png
- image002.jpg
- image002.png
- image003.jpg
- image003.png
it works individually but I din't know how to write the .bat to do it all in just few seconds with a script....

Any kind of help will be appreciate, I didn't know how to write a .bat file....
Thanks in advance !
Best Regards,
Christian

Re: bat file for compose .jpg .png with same name

Posted: 2019-03-04T09:25:13-07:00
by snibgo
ChristianK wrote:"C:\Program Files\ImageMagick\magick.exe" *.jpg ( *.png" -negate ) -alpha off -compose copy_opacity -composite
That command would read all the jpg image and all the png images, then would fail because "-composite" needs two or three inputs, not thousands (see http://www.imagemagick.org/script/comma ... #composite). And you have no output filename.

Do you have enough memory to read all the png and jpg images? If so, you could use "-layers composite". See http://www.imagemagick.org/script/comma ... php#layers. Otherwise, you could write a simple magick command that processes one pair of images. Then put that inside a shell loop.

Re: bat file for compose .jpg .png with same name

Posted: 2019-03-04T10:16:22-07:00
by ChristianK
snibgo wrote :
Otherwise, you could write a simple magick command that processes one pair of images. Then put that inside a shell loop.
It's exactly what I want to have, but didn't know how to do it :

I searching a way to tell in a .bat file something like this but I'm not developper :

- In a folder where my images are
- for each images
- select file with the same name with .jpg and .png extension
- do "C:\Program Files\ImageMagick\magick.exe" filename.jpg ( filename.png" -negate ) -alpha off -compose copy_opacity -composite filename-ok.png

somethings like this, so it take each pair of file (same name, .jpg and .png format) and the compose them....
But i didn't know how to write it in a good syntax windows understand....

Best Regard,
Christian

Re: bat file for compose .jpg .png with same name

Posted: 2019-03-04T10:50:46-07:00
by snibgo
I would do it with a "for" shell loop. Type "help for" to see the syntax.

Re: bat file for compose .jpg .png with same name

Posted: 2019-03-05T06:20:42-07:00
by ChristianK
Thanks for your answer snibgo,
I write this but nothings happen....


FOR %%I in ("\\1xx.x.x.x\input2\working\01-compose\*.jpg") do
( if exist ("\\1xx.x.x.x\input2\working\01-compose\%%~nI.png")
"C:\Program Files\ImageMagick\magick.exe" "%%I.jpg" ( "%%I.png" -negate ) -alpha off -compose copy_opacity -composite "%%I-ok.png"
)

If I test the command alone with one.jpg and .png it works, so it's not the magick command...
but when I try with the loop, the cmd windows appears and disappears quickly.... and did'nt see what's going wrong.

So I put "PAUSE' after all in the .bat file, but nothing more, the cmd windows didn't stay on screen.....

Re: bat file for compose .jpg .png with same name

Posted: 2019-03-05T08:19:33-07:00
by snibgo
ChristianK wrote:the cmd windows appears and disappears quickly
I suggest you open a command window (aka "dos" window). Change to whatever directory you want, then use whatever text editor you want to create a BAT script file. Then run that script file by typing its name at the prompt.

Your syntax for "if exist" is wrong. Type "help if" for the correct syntax.

Re: bat file for compose .jpg .png with same name

Posted: 2019-03-05T10:04:11-07:00
by ChristianK
Thx for your help Snibgo, I appreciate !

In fact, it seems that I have mistake with parenthesis...
in my command I need this : must -negate the .png

%%I ( %%I.png -negate) -alpha off etc....

and it doesn't work because of the For ... do . ..

the parenthesis is use for windows....

Did you know how can I do for it works ?

Thanks !

Re: bat file for compose .jpg .png with same name

Posted: 2019-03-05T10:19:56-07:00
by ChristianK
Snibgo,

it works ! I found , just put parentehsis inside double quotes and it's works !
Thx again for your help !
Best Regards,
Christian

Re: bat file for compose .jpg .png with same name

Posted: 2019-03-05T13:55:26-07:00
by fmw42
%%I ( %%I.png -negate) -alpha off etc....
You need a space between -negate and )