Page 1 of 1

Convert SVG to JPG is generating blank image

Posted: 2011-10-27T03:51:14-07:00
by bencrosthwaite
Hello Everyone,

This is my first time posting in this forum so i apologise if its in the wrong section.

I am trying using imagemagic to convert some SVG images to JPG. I am doing this within a PHP page. The problem is that the generated JPG are blank. I am new to ImageMagick and not sure what my problem is here.

The command i am using to make the conversion to JPG is:

Code: Select all

shell_exec("/usr/local/bin/convert <path>/cardoutsideleft.svg <path>/ar.jpg");
The SVG i am using is:

Code: Select all

<?xml version='1.0' encoding='UTF-8'?>
<svg xmlns:xlink='http://www.w3.org/1999/xlink' xmlns:svg='http://www.w3.org/2000/svg' width='396.850393695' height='559.370078732' version='1.1'>
	<g id='layer1'>
		<text x='15.6' y='44.75' font-size='40' font-face='Arial' fill='#FF0000'>
			<tspan x='15.6' y='44.75'>Happy 21st Birthday</tspan>
		</text>
		
		<image x='-36.6' y='252.6' width='471' height='352' xlink:href='birthday-cake2.png' />\
	</g>
</svg>
I would greatly appreciate some input.

Regards,
-Ben

Re: Convert SVG to JPG is generating blank image

Posted: 2011-10-27T05:16:23-07:00
by anthony
Your SVG code seems to work well for me. Though it can not find the external "birthday-cake2.png" image file.

Can you convert other images to JPEG?

Code: Select all

  convert rose: rose.jpg
What about SVG to other image formats

Code: Select all

 convert file.svg file.png
What type of SVG converter are you using MSVG or RSVG
See SVG handling for details
http://www.imagemagick.org/Usage/draw/#svg

NOTE that RSVG (a external delegate library) is generally preferred, though either method works fine.

Re: Convert SVG to JPG is generating blank image

Posted: 2011-10-27T05:41:16-07:00
by bencrosthwaite
Thanks for your reply Anthony.

I was able to convert the rose with no problems. I tried converting to a PNG but had the same problem as with JPGs.

I read through the link you gave me. In the section "To find out what your IM will do use... " i used the command they used but i got a different output:

Code: Select all

SVG* SVG       rw+   Scalable Vector Graphics (XML 2.6.11)
SVGZ* SVG       rw+   Compressed Scalable Vector Graphics (XML 2.6.11)
Im still getting my head around how ImageMagick works but it seems I am neither using RSVG or MSVG. If this is the case, would this be the root of my problem? and do you know how i would go about fixing this?

Regards,
-Ben

Re: Convert SVG to JPG is generating blank image

Posted: 2011-10-27T20:19:52-07:00
by anthony
What is in the extra external image the SVG is reading.

Re: Convert SVG to JPG is generating blank image

Posted: 2011-10-28T03:21:20-07:00
by bencrosthwaite
Do you mean this line of code?

Code: Select all

<image x='-36.6' y='252.6' width='471' height='352' xlink:href='birthday-cake2.png' />
Its just a png image

Regards,
-Ben

Re: Convert SVG to JPG is generating blank image

Posted: 2011-10-28T05:20:10-07:00
by bencrosthwaite
OK, i have a new problem.

I went through the process of installing the RSVG delegate. Now when i use the following command:

Code: Select all

convert -list format | grep SVG
I get the following output

Code: Select all

MSVG  SVG       rw+   ImageMagick's own SVG internal renderer
      SVG  SVG       rw+   Scalable Vector Graphics (RSVG 2.34.1)
     SVGZ  SVG       rw+   Compressed Scalable Vector Graphics (RSVG 2.34.1)
All is good, now i can convert SVG images to JPG and PNG in the terminal. Brilliant.

The problem is now when i try execute the command in PHP, it seems to be ignored and no jpg image is generated.

Code: Select all

shell_exec("/usr/local/bin/convert <path>/cardoutsideleft.svg <path>/ar.jpg");
Any ideas?

Regards,
-Ben