Issue in svg to png

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Locked
kunal
Posts: 7
Joined: 2019-12-26T00:55:19-07:00
Authentication code: 1152

Issue in svg to png

Post by kunal »

Hi All,

I use php imagemagick for convert svg to png, but code is not convert it properly.

this is my code.

Code: Select all

<?php
        $im = new Imagick();        
        $svg = file_get_contents($link);        
        $im->setBackgroundColor(new ImagickPixel('transparent'));        
        $im->readImageBlob($svg);
        $im->setImageFormat("png32");        
        $im->writeImage($path.$file.".png");
        $im->clear();
        $im->destroy(); 
?>
My imagick version is 3.4.4
This original svg image.
Image

After I convert it in png
Image

My imagick version
Image

Please help to solve this.
Last edited by kunal on 2019-12-27T22:53:29-07:00, edited 1 time in total.

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Issue in svg to png

Post by snibgo »

You have linked to two PNG files. Please link to your SVG file.
snibgo's IM pages: im.snibgo.com

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

Re: Issue in svg to png

Post by fmw42 »

Please identify your version of ImageMagick (not Imagick) and what SVG renderer that ImageMagick is using.

246246
Posts: 200
Joined: 2015-07-06T07:38:22-07:00
Authentication code: 1151

Re: Issue in svg to png

Post by 246246 »

I can download the svg from the original post, and just convert it to png with recent ImageMagick that uses default setting:

<delegate decode="svg" command="&quot;rsvg-convert&quot; -o &quot;%o&quot; &quot;%i&quot;"/>

from command line magick. No problem happened.

Version: ImageMagick 7.0.9-11 Q16 x64 2019-12-26 http://www.imagemagick.org

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

Re: Issue in svg to png

Post by fmw42 »

The svg file converts fine for me using IM 6.9.10.81 with Inkscape as the renderer. ImageMagick can use one of 3 SVG renderers: MSVG/XML (ImageMagick default internal renderer), RSVG delegate, Inkscape. You are likely using the IM internal one. Try installing either RSVG as a delegate to ImageMagick or just install Inkscape and ImageMagick will use it. They are much better renderers than the MSVG/XML default.

User avatar
magick
Site Admin
Posts: 11254
Joined: 2003-05-31T11:32:55-07:00

Re: Issue in svg to png

Post by magick »

We checked the internal renderer in the lastest release of ImageMagick. It returns the expected rendering of the SVG image:

Code: Select all

magick -density 300 msvg:14cesclogostore.svg 14cesclogostore.png

kunal
Posts: 7
Joined: 2019-12-26T00:55:19-07:00
Authentication code: 1152

Re: Issue in svg to png

Post by kunal »

snibgo wrote:
2019-12-26T05:10:51-07:00
You have linked to two PNG files. Please link to your SVG file.
The first image is svg image and second one is png after convert with php imagick

kunal
Posts: 7
Joined: 2019-12-26T00:55:19-07:00
Authentication code: 1152

Re: Issue in svg to png

Post by kunal »

fmw42 wrote:
2019-12-26T10:25:07-07:00
Please identify your version of ImageMagick (not Imagick) and what SVG renderer that ImageMagick is using.
imagick module version: 3.4.4
imagick classes : Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator
Imagick compiled with ImageMagick version : ImageMagick 6.7.2-7 2017-03-22 Q16 http://www.imagemagick.org
Imagick using ImageMagick library version : ImageMagick 6.7.2-7 2017-03-22 Q16 http://www.imagemagick.org
ImageMagick copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
ImageMagick release date: 2017-03-22

don't know SVG renderer that ImageMagick, how can I know this?
Image

kunal
Posts: 7
Joined: 2019-12-26T00:55:19-07:00
Authentication code: 1152

Re: Issue in svg to png

Post by kunal »

246246 wrote:
2019-12-27T01:11:08-07:00
I can download the svg from the original post, and just convert it to png with recent ImageMagick that uses default setting:

<delegate decode="svg" command="&quot;rsvg-convert&quot; -o &quot;%o&quot; &quot;%i&quot;"/>

from command line magick. No problem happened.

Version: ImageMagick 7.0.9-11 Q16 x64 2019-12-26 http://www.imagemagick.org
How can I use this with php ImageMagick class.
Please see ImageMagick version.

Image

kunal
Posts: 7
Joined: 2019-12-26T00:55:19-07:00
Authentication code: 1152

Re: Issue in svg to png

Post by kunal »

fmw42 wrote:
2019-12-27T12:44:50-07:00
The svg file converts fine for me using IM 6.9.10.81 with Inkscape as the renderer. ImageMagick can use one of 3 SVG renderers: MSVG/XML (ImageMagick default internal renderer), RSVG delegate, Inkscape. You are likely using the IM internal one. Try installing either RSVG as a delegate to ImageMagick or just install Inkscape and ImageMagick will use it. They are much better renderers than the MSVG/XML default.
I edit my original post attached ImageMagick version, this version is ok for svg to png or I want to upgrade version.

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

Re: Issue in svg to png

Post by fmw42 »

ImageMagick 6.7.2.7 is ancient (almost 3 years old). I would suggest that you upgrade it. I would also suggest installing Inkscape on your system where ImageMagick can find it in your PATH. That way, ImageMagick will use that over the IM internal one, which may not be so good. However, the ImageMagick developer says that it converted fine using the current ImageMagick and the built-in MSVG renderer. So perhaps just upgrading ImageMagick will fix your issue, since many bug fixes have been made in 3 years.

kunal
Posts: 7
Joined: 2019-12-26T00:55:19-07:00
Authentication code: 1152

Re: Issue in svg to png

Post by kunal »

fmw42 wrote:
2019-12-27T23:44:34-07:00
ImageMagick 6.7.2.7 is ancient (almost 3 years old). I would suggest that you upgrade it. I would also suggest installing Inkscape on your system where ImageMagick can find it in your PATH. That way, ImageMagick will use that over the IM internal one, which may not be so good. However, the ImageMagick developer says that it converted fine using the current ImageMagick and the built-in MSVG renderer. So perhaps just upgrading ImageMagick will fix your issue, since many bug fixes have been made in 3 years.
Thanks for quick reply.
I will try to upgrade my imagick version.
One quick question can ImageMagick automatically find Inkscape or I need to do something?
also my php version is 5.5.35 can latest ImageMagick version compatible with that version?

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

Re: Issue in svg to png

Post by fmw42 »

You need to upgrade ImageMagick not Imagick.

I suppose it depends upon how you install Inkscape. If it is in your $PATH environment variable, then I would think that IM can find it.

I know nothing about what versions of PHP support current versions of ImageMagick.

I would suggest first trying to install Inkscape and see what happens from there.

kunal
Posts: 7
Joined: 2019-12-26T00:55:19-07:00
Authentication code: 1152

Re: Issue in svg to png

Post by kunal »

fmw42 wrote:
2019-12-28T11:04:03-07:00
You need to upgrade ImageMagick not Imagick.

I suppose it depends upon how you install Inkscape. If it is in your $PATH environment variable, then I would think that IM can find it.

I know nothing about what versions of PHP support current versions of ImageMagick.

I would suggest first trying to install Inkscape and see what happens from there.
Thanks.

Locked