Overlay SVG image onto JPEG (watermark)

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
djeyewater
Posts: 15
Joined: 2009-07-25T09:16:08-07:00
Authentication code: 8675309

Overlay SVG image onto JPEG (watermark)

Post by djeyewater »

I would like to overlay an SVG image on top of a raster image so that the SVG image's width is 20% of the raster image's width and is placed 10% in from the bottom left edge of the image.

I've tried the following command, but it doesn't seem to affect the size or offset of the SVG at all, plus the SVG is rendered with a white background rather than being transparent:

Code: Select all

composite -compose atop -geometry "20%+10%" -gravity southwest watermark.svg photo.jpg photo-watermarked.jpg
You can see the result image here: http://www.iliveinabin.com/ImageMagick- ... marked.jpg
Made from this SVG: http://www.iliveinabin.com/ImageMagick- ... ermark.svg
And this photo: http://www.iliveinabin.com/ImageMagick- ... /photo.jpg

I realise I can get the end result I'm looking for by using a PNG and pixel values for the geometry, but ideally I'd like to get the more flexible solution using an SVG working.

Thanks

Dave
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Overlay SVG image onto JPEG (watermark)

Post by fmw42 »

I am not sure that -geometry using % values. If it does then you still need the + sign. If it does not, then you need to convert the % values to pixels. see http://www.imagemagick.org/script/comma ... p#geometry in the section about offsets. It looks like it does not support %.

Also you should use the convert syntax and set the density on the svg file before reading it to set the size of the converted svg file.

something like

convert photo.jpg -density XX watermark.svg -gravity southwest -geometry "+X+Y" -compose atop photo-watermarked.jpg
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Overlay SVG image onto JPEG (watermark)

Post by snibgo »

The converted SVG image has no transparency because, by defalt, IM puts it on an opaque white background. Defeat this by putting "-background none" before the SVG file. The only transparency occurs in the top corners.

You might choose a different "-compose" operation. Perhaps "-compose Multiply" gives what you want.
snibgo's IM pages: im.snibgo.com
djeyewater
Posts: 15
Joined: 2009-07-25T09:16:08-07:00
Authentication code: 8675309

Re: Overlay SVG image onto JPEG (watermark)

Post by djeyewater »

Thanks for the suggestions, after adding -background none I was still having an issue with opacity of the SVG shape being 100% rather than the 50% set in the SVG. I did some searching and found that rather than setting opacity on the <g> containing the shape path, fill-opacity="0.5" should be set on the path that makes up the shape. All working how I wanted now.

Thanks again!

Dave
Post Reply