Overlay a SVG image on top of a png image

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
yervand
Posts: 5
Joined: 2013-06-24T14:45:51-07:00
Authentication code: 6789

Overlay a SVG image on top of a png image

Post by yervand »

Hello

Im trying to convert a pdf file to a png and then place a svg image on top of the png.

The svg contains a white background which I would like it to be transparent when placing over the png. Can someone please help me accomplish this.

I know that (in php)

exec('convert /file/filepdf.pdf /file/filepng.png');

converts the file to a png and I tried adding the following command to it to make it overlay the svg but it doesnt seem to work

exec('convert /file/filepdf.pdf /file/filepng.png -composite /file/svgfile.svg'); hoping this will place the svg file above the converted png but no luck.

Any suggestions on how i can accomplish this?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Overlay a SVG image on top of a png image

Post by Bonzo »

I would apply the svg and then change to png; something like:

Code: Select all

exec('convert /file/filepdf.pdf \( /file/svgfile.svg -fuzz 10% -transparent white \) -gravity center -composite /file/filepng.png '); 
yervand
Posts: 5
Joined: 2013-06-24T14:45:51-07:00
Authentication code: 6789

Re: Overlay a SVG image on top of a png image

Post by yervand »

Bonzo

This doesnt seem to work

I get the following error in my logs

convert: Memory allocation failed `/file/svgfile.svg' @ svg.c/ReadSVGImage/2825.
convert: missing an image filename `/file/filepng.png ' @ convert.c/ConvertImageCommand
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Overlay a SVG image on top of a png image

Post by fmw42 »

post links to your pdf and svg files so others can look at them and work with them
Post Reply