Page 1 of 1

Issue in svg to png

Posted: 2019-12-26T01:22:11-07:00
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.

Re: Issue in svg to png

Posted: 2019-12-26T05:10:51-07:00
by snibgo
You have linked to two PNG files. Please link to your SVG file.

Re: Issue in svg to png

Posted: 2019-12-26T10:25:07-07:00
by fmw42
Please identify your version of ImageMagick (not Imagick) and what SVG renderer that ImageMagick is using.

Re: Issue in svg to png

Posted: 2019-12-27T01:11:08-07:00
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

Re: Issue in svg to png

Posted: 2019-12-27T12:44:50-07:00
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.

Re: Issue in svg to png

Posted: 2019-12-27T13:14:31-07:00
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

Re: Issue in svg to png

Posted: 2019-12-27T22:23:30-07:00
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

Re: Issue in svg to png

Posted: 2019-12-27T22:32:26-07:00
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

Re: Issue in svg to png

Posted: 2019-12-27T22:39:01-07:00
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

Re: Issue in svg to png

Posted: 2019-12-27T22:59:04-07:00
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.

Re: Issue in svg to png

Posted: 2019-12-27T23:44:34-07:00
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.

Re: Issue in svg to png

Posted: 2019-12-28T01:23:00-07:00
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?

Re: Issue in svg to png

Posted: 2019-12-28T11:04:03-07:00
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.

Re: Issue in svg to png

Posted: 2019-12-29T22:12:00-07:00
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.