Page 1 of 2

How can I add a different logos to an image in batch with the same filenames?

Posted: 2018-05-09T17:16:32-07:00
by Robin55
Hello All, I just need a bit of help here?
The version of ImageMagick I am using is 7.0.7-27 Q16 x64 and I am on Windows 10

This is what I currently have made, Their just simple boxes I have created. (I'm no Photoshop expert obviously)

Image

What I want to do is add a logo to the flattened out spine and do it in a batch process. All the logos have the same file names as the flattened boxes. So I basically want to combine the two. Basically create a bat file that will add the all my logos with the same file name as the flattened out covers with the same file name. The logos are also different sizes so I imagine they would have to be treated as labels so they fit correctly?
I would really like to get this done so any help would be greatly appreciated!!

This is what the box looks like like stretched out:

Image

This is the Logo I want to add to the stretched out image:

Image

And this is the result I am looking for:

Image

Re: How can I add a logo to an image in batch?

Posted: 2018-05-09T19:31:49-07:00
by Robin55
This is as close as I have got:

for %%F in (Spine\*.png) do magick composite -rotate -90 -geometry +31+105 "Spine\%%~nF.png" "Front Covers\%%~nF.png" "Covers\%%~nF.png"

Re: How can I add a logo to an image in batch?

Posted: 2018-05-09T23:13:46-07:00
by fmw42
i do not believe you can rename output in mogrify. You should consider using a script to loop over your image with convert in IM 6 or use a multi-image solution in IM 7

Re: How can I add a logo to an image in batch?

Posted: 2018-05-10T02:18:33-07:00
by Robin55
Hi fmw42,
I don't want to rename the output, the two files I'm combining would have the same filenames and so would the file that is output.... hopefully
Anymore help with this would be very appreciated?

Re: How can I add a logo to an image in batch?

Posted: 2018-05-10T03:53:09-07:00
by snibgo
This problem, like so many, can be split into:

1. Decide the image processing required.

2. Decide the looping requirements.

For 1: You don't need "magick composite". Instead, I suggest "magick ... -composite".

The space on the spine is approximately 50x533 pixels. So the rotated logo has to fit into that size. This is:

Code: Select all

-rotate 90 -resize "50x533>"
The ">" prevents small logos from being enlarged. But you might not want that.

So the basic IM command is:

Code: Select all

magick ^
  vi2x6a.png ^
  ( 20gjf43.png -rotate 90 -resize "50x533>" ) ^
  -gravity SouthWest -geometry +28+30 -composite ^
  x.png
Then put that in a for loop as you have done, using %%~nF with the appropriate dirctories for the two inputs and output.

Re: How can I add a logo to an image in batch?

Posted: 2018-05-10T04:17:01-07:00
by Robin55
Thank you SO much snibgo!! I don't have time right now to test this out, but I'll let you know how I got on as soon as I can. I never would of worked all that out :)

Re: How can I add a logo to an image in batch?

Posted: 2018-05-10T22:15:12-07:00
by Robin55
Is this what you mean snibgo? I can get this working for individual files like your first example, but I'm not able to get it going in batch? can you help me fix this?

magick ^
"Front Covers\%%~nF.png" ^
( "Spine\%%~nF.png" -rotate 90 -resize "50x533>" ) ^
-gravity SouthWest -geometry +26+80 -composite ^
"Covers\%%~nF.png"

Re: How can I add a logo to an image in batch?

Posted: 2018-05-10T22:52:17-07:00
by snibgo
Yes, but you need "for ... in ... do ..." at the start:

Code: Select all

for %%F in (Spine\*.png) do magick ^
"Front Covers\%%~nF.png" ^
( "Spine\%%~nF.png" -rotate 90 -resize "50x533>" ) ^
-gravity SouthWest -geometry +26+80 -composite ^
"Covers\%%~nF.png"

Re: How can I add a logo to an image in batch?

Posted: 2018-05-10T23:17:00-07:00
by Robin55
Sorry snibgo but its still not working for me, when I run the .bat file all I get is a file named: ^ I tried removing the ^ on the last line and the first line but it hasn't made a difference...what am I missing???

Re: How can I add a logo to an image in batch?

Posted: 2018-05-10T23:37:49-07:00
by snibgo
Do you get any error messages?

Check you don't have any spaces after the ^ line-continuation-character.

Please paste your exact command here.

Re: How can I add a logo to an image in batch?

Posted: 2018-05-10T23:42:19-07:00
by Robin55
Yes I defiantly have no spaces after the ^ in the bat file.
This is the code:

for %%F in (Spine\*.png) do magick ^
"Front Covers\%%~nF.png" ^
( "Spine\%%~nF.png" -rotate 90 -resize "50x533>" ) ^
-gravity SouthWest -geometry +26+80 -composite ^
"Covers\%%~nF.png"

Re: How can I add a logo to an image in batch?

Posted: 2018-05-11T00:15:13-07:00
by snibgo
When I create the three directories and put PNG files in the first two, it works fine for me.

Does your BAT file contain anything else? If it does, remove it until you get the IM stuff working.

Check what files you have. What is the output from:

Code: Select all

dir "Front Covers"
dir "Spine"
dir "Covers"
Insert this before the for loop:

Code: Select all

for %%F in (Spine\*.png) do echo %%~nF
This should list the files in Spine\.

Re: How can I add a logo to an image in batch?

Posted: 2018-05-11T00:38:30-07:00
by Robin55
I have checked my files they are 2 .png files in Front Covers, 2 .png files in spines. if I insert

for %%F in (Spine\*.png) do echo %%~nF

I get the same results, the command line looks like its working but nothing is output apart from the file named: ^
I don't know if this is any use but when I run the bat directly from a cmd window I get the error message

' "Front Covers\%%~nF.png" ' is not recognized as an internal or external command

Thanks for your time and patience so far snibgo

Re: How can I add a logo to an image in batch?

Posted: 2018-05-11T01:14:16-07:00
by snibgo
wrote:... when I run the bat directly from a cmd window ...
I suppose you mean: when you run that command directly from the CMD line instead of in a BAT script. Yes, the doubled %% is needed only for BAT scripts. At the command line they should be single %.

I don't know what else to suggest. Perhaps simplify the magick command, eg:

Code: Select all

for %%F in (Spine\*.png) do magick ^
"Front Covers\%%~nF.png" ^
"Covers\%%~nF.png"

Code: Select all

for %%F in (Spine\*.png) do magick ^
"Front Covers\%%~nF.png" ^
"Spine\%%~nF.png" ^
-gravity SouthWest -geometry +26+80 -composite ^
"Covers\%%~nF.png"

Code: Select all

for %%F in (Spine\*.png) do magick ^
"Front Covers\%%~nF.png" ^
( "Spine\%%~nF.png" ) ^
-gravity SouthWest -geometry +26+80 -composite ^
"Covers\%%~nF.png"

Re: How can I add a logo to an image in batch?

Posted: 2018-05-11T01:32:39-07:00
by Robin55
Ok so I tried all your codes and everyone of them produced a file named: ^
However if I put your code all in one line and remove the ^ I do get a result though the spine.png is placed in the bottom right corner and is not where it should be....
do you think you could show me how to write the code properly all on the one line? thanks again for your help so far!