bat file for compose .jpg .png with same name

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
ChristianK
Posts: 10
Joined: 2019-03-04T08:44:14-07:00
Authentication code: 1152

bat file for compose .jpg .png with same name

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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.
snibgo's IM pages: im.snibgo.com
ChristianK
Posts: 10
Joined: 2019-03-04T08:44:14-07:00
Authentication code: 1152

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

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post by snibgo »

I would do it with a "for" shell loop. Type "help for" to see the syntax.
snibgo's IM pages: im.snibgo.com
ChristianK
Posts: 10
Joined: 2019-03-04T08:44:14-07:00
Authentication code: 1152

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

Post 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.....
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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.
snibgo's IM pages: im.snibgo.com
ChristianK
Posts: 10
Joined: 2019-03-04T08:44:14-07:00
Authentication code: 1152

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

Post 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 !
ChristianK
Posts: 10
Joined: 2019-03-04T08:44:14-07:00
Authentication code: 1152

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

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post by fmw42 »

%%I ( %%I.png -negate) -alpha off etc....
You need a space between -negate and )
Post Reply