Page 1 of 1
Overlaying a watermark/logo on multiple images of multiple dimensions
Posted: 2018-04-02T07:48:19-07:00
by instrumentally
I have an image (JPG format) that I wish to "brand" (like a cowboy branding a cow) with a logo, center justified. I want to preserve the original. IOW, I want a new copy of the original base image with the branding/watermark placed on top of the new copy, saved off into a separate target folder. The resulting new image will be of the same dimensions as the original base file.
I understand that ImageMagick does allow two images to be merged/combined, but I fail to find anything in the documentation that addresses how to scale one image (the overlaid branding logo) to match (roughly) the dimensions of the underlying image.
The image that will overlay the other will have a transparent background. If need be, I can create a SVG for this purpose, so that it will scale without distortion. My question is, therefore, how to get the "branding" image to reflect (roughly) the dimensions of the base image. I surely don't want to place a 1000x1000 "branded" logo over top of a 300x300 base image. Nor would I want to have a 100x100 logo placed on 3000x3000 image. I would like to be able to maintain a fairly consistent ratio between the overlaid image with the base image. It doesn't have to be perfect, but I don't want the overlaid image to be chopped off by the original frame dimensions of the base image, nor do I want the ovelaid image to become a small blip on the base image.
Re: Overlaying a watermark/logo on multiple images of multiple dimensions
Posted: 2018-04-02T08:27:00-07:00
by Bonzo
What version of Imagemagick are you using?
Have you tried searching the forum as there were similar post last year?
viewtopic.php?f=1&t=30890&p=150443&hili ... rk#p150443
viewtopic.php?f=1&t=32784&p=150159&hili ... rk#p150159
Re: Overlaying a watermark/logo on multiple images of multiple dimensions
Posted: 2018-04-02T10:15:44-07:00
by fmw42
Please, always provide your IM version and platform when asking questions, since syntax may differ. Also provide your exact command line and if possible your images.
See the top-most post in this forum "IMPORTANT: Please Read This FIRST Before Posting" at
http://www.imagemagick.org/discourse-se ... f=1&t=9620
For novices, see
http://www.imagemagick.org/discourse-se ... f=1&t=9620
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
https://github.com/ImageMagick/usage-markdown
See for example:
https://www.imagemagick.org/Usage/compose/#watermark
https://www.imagemagick.org/Usage/layers/#convert
If you provide your two input images, we can help further.
(unix syntax for IM 6)
Code: Select all
pct=33
amt=`convert -ping monet2.jpg -format "%[fx:$pct*min(w,h)/100]" info:`
convert monet2.jpg \( flatten_xor.png -resize $amt \) -gravity center -compose over -composite monet_watermark.png
Re: Overlaying a watermark/logo on multiple images of multiple dimensions
Posted: 2018-04-03T19:21:14-07:00
by instrumentally
I am using version 7.0.1-Q16
pct=33
amt=`convert -ping monet2.jpg -format "%[fx:$pct*min(w,h)/100]" info:`
convert monet2.jpg \( flatten_xor.png -resize $amt \) -gravity center -compose over -composite monet_watermark.png
How are you supposed to accomplish the above on a Windows box at a c:> prompt (assuming I'm in the ImageMagick folder)?
Re: Overlaying a watermark/logo on multiple images of multiple dimensions
Posted: 2018-04-03T21:45:06-07:00
by GeeMack
instrumentally wrote: ↑2018-04-03T19:21:14-07:00How are you supposed to accomplish the above on a Windows box at a c:> prompt (assuming I'm in the ImageMagick folder)?
Using IM7 at a Windows CMD prompt, a command like this will read in both images, resize the logo to fit within a box 90% the width and height of the base image, and overlay the resized logo centered on the base image.
Code: Select all
magick input.png logo.png ^
-resize %[fx:t?u.w*0.9:u.w]x%[fx:t?u.h*0.9:u.h] -gravity center -composite output.png
To use this in a BAT script you'll need to change those single percent signs "%" into doubles "%%".
Re: Overlaying a watermark/logo on multiple images of multiple dimensions
Posted: 2018-04-03T23:44:10-07:00
by fmw42
GeeMack: Would it not be better to just resize the logo. You spend effort resizing the input.png even though it does change it's size.
You can correct me here on my IM 7 Windows syntax using my examples above. It works in IM 7 Unix by adding \ before the parens.
Code: Select all
magick monet2.jpg -set option:dim "%[fx:max(u.w,u.h)*33/100]" ( flatten_xor.png -resize "%[dim]" ) -gravity center -compose over -composite monet_watermark.png
Re: Overlaying a watermark/logo on multiple images of multiple dimensions
Posted: 2018-04-04T06:01:10-07:00
by instrumentally
Thanks to everyone, however, the logo image I am trying to overlay is a SVG file, and despite the fact that the SVG has a transparent background, the overlaid image is coming in with a white background in the resulting output file. How do I maintain the SVG's transparent background in this operation? The image in question can be found here:
http://hostsafe.com/temp/in.svg
Re: Overlaying a watermark/logo on multiple images of multiple dimensions
Posted: 2018-04-04T06:11:03-07:00
by instrumentally
Also a problem is that even if I have my visible SVG elements defined with 50% opacity, the resulting magick merge ignores the opacity value. The above hyperlink to the SVG has 50% opacity for the two black elements found therein.
Re: Overlaying a watermark/logo on multiple images of multiple dimensions
Posted: 2018-04-04T08:16:08-07:00
by GeeMack
fmw42 wrote: ↑2018-04-03T23:44:10-07:00GeeMack: Would it not be better to just resize the logo. You spend effort resizing the input.png even though it does change it's size.
The FX expressions in my example resize the second image to 90% the size of the first, and resize the first image to its own size. I don't know the internals, but my understanding is that resizing to its same dimensions comes at almost no cost. A quick test shows your method might be 0.01 second faster, maybe because it's only doing one FX calculation. I don't know.
You can correct me here on my IM 7 Windows syntax using my examples above. It works in IM 7 Unix by adding \ before the parens.
Code: Select all
magick monet2.jpg -set option:dim "%[fx:max(u.w,u.h)*33/100]" ( flatten_xor.png -resize "%[dim]" ) -gravity center -compose over -composite monet_watermark.png
Yes, that works in Windows as-is.
Re: Overlaying a watermark/logo on multiple images of multiple dimensions
Posted: 2018-04-04T13:05:53-07:00
by snibgo
instrumentally wrote:How do I maintain the SVG's transparent background in this operation?
Prefix the svg name with "-background None".
So, using GeeMack's method, adding a few line-breaks for clarity, Windows CMD syntax:
Code: Select all
magick ^
input.png ^
-background none in.svg ^
-resize %[fx:t?u.w*0.9:u.w]x%[fx:t?u.h*0.9:u.h] ^
-gravity center -composite ^
output.png
Re: Overlaying a watermark/logo on multiple images of multiple dimensions
Posted: 2018-04-04T14:52:47-07:00
by fmw42
If your svg renders small or is not good resolution, then for better quality add -density XX before in.svg with XX=300 or so, to be sure you get a high quality result. Note that too large a density will slow things down.
Re: Overlaying a watermark/logo on multiple images of multiple dimensions
Posted: 2018-04-12T16:55:37-07:00
by instrumentally
-background none
Dilemma...
If I have two images that I am working with, how does one handle the situation where the base picture is a PNG file with a transparent background however I want that transparent background placed on a white background AND...AND!!...AND...the watermark image being placed on top of the base picture is also a PNG with a transparent background and in this case, I want the background to remain transparent.
Using "-background none" doesn't accomplish both.
Re: Overlaying a watermark/logo on multiple images of multiple dimensions
Posted: 2018-04-12T17:35:22-07:00
by snibgo
You have a png image you want to flatten against white, then want to composite over that an svg with transparency. Is that correct? Then just do those operations:
Code: Select all
magick ^
input.png ^
-background White -layers Flatten ^
-background none in.svg ^
-resize %[fx:t?u.w*0.9:u.w]x%[fx:t?u.h*0.9:u.h] ^
-gravity center -composite ^
output.png
Re: Overlaying a watermark/logo on multiple images of multiple dimensions
Posted: 2018-04-14T10:46:53-07:00
by instrumentally
Thank you to all who have helped.