I am having an issue with converting a SVG image to PNG with PHP using IMagick and preserving opacity on some SVG elements. I had a windows server and used Imagick from command line to convert SVG to PNG and everything worked great. I am now switching to PHP website on a unix server and I am using PHP IMagick.
It converts the file and preserves background transparency fine. I have a bunch of elements in the SVG that get turned on and off and then converted to a PNG. The PHP IMagick does not seem to handle opacity on an element in SVG though. If I view the SVG in my browser it is correct, just the converted file is incorrect.
I have tried the following on elements and none of them seem to hide the elements.
style="opacity: 0;"
opacity="0"
visibility="hidden"
Is this a known issue with Imagick or am I missing something here.
Convert SVG image to PNG with PHP Imagick and preserve opacity on elements
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Convert SVG image to PNG with PHP Imagick and preserve opacity on elements
ImageMagick uses a delegate to rasterize SVGs. Perhaps your two versions (command line, and via IMagick) use two different rasterizers.
snibgo's IM pages: im.snibgo.com
Re: Convert SVG image to PNG with PHP Imagick and preserve opacity on elements
How would I go about finding out what delegate each uses?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Convert SVG image to PNG with PHP Imagick and preserve opacity on elements
I do not know about Imagick. But in Imagemagick, you can do the command
and look at the line for SVG. It should say (RSVG, XML/MSVG or Inkscape)
Code: Select all
convert -list format
Re: Convert SVG image to PNG with PHP Imagick and preserve opacity on elements
When I run:
convert -list format
I get:
SVG SVG rw+ Scalable Vector Graphics (XML 2.9.4)
convert -list format
I get:
SVG SVG rw+ Scalable Vector Graphics (XML 2.9.4)
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Convert SVG image to PNG with PHP Imagick and preserve opacity on elements
That means it is using the Imagemagick internal SVG renderer, which is the worst of the 3. The best is to install Inkscape on your system. Imagemaick will use that if it can find it on your system. Second is to install the RSVG delegate library and recompile Imagemagick with it added.
My guess is neither is installed such that Imagick can access it. So it defaults to the Imagemagick MSVG/XML.
My guess is neither is installed such that Imagick can access it. So it defaults to the Imagemagick MSVG/XML.
Re: Convert SVG image to PNG with PHP Imagick and preserve opacity on elements
I installed Inkscape and that seems to have fixed everything.
Thank you so much!!!! I have been struggling with this for hours.
Thank you so much!!!! I have been struggling with this for hours.