php - Converting SVG to PNG with ImageMagic ignores fill pattern url -


i using php's imagick class convert svg png.

the conversion succeeds seems ignore fill patterns. here code:

<?php  $svg = <<<svg <?xml version="1.0"?> <svg>     <defs>         <pattern id="mypattern" x="0" y="0" width="20" height="20" patternunits="userspaceonuse">             <rect width="20" height="20" fill="#ffffff" />              <circle cx="10" cy="10" r="5" stroke="#0000bb" fill="#dd8d8d" />          </pattern>     </defs>     <text y="100%"         stroke="#ff0000"         fill="url('#mypattern')"         font-size="40pt">         hello <tspan style="font-style: italic">svg</tspan> world!     </text> </svg> svg;  try{      $image = new imagick();     $image->setbackgroundcolor(new imagickpixel('transparent'));     $image->readimageblob( $svg );     $image->setimageformat('png32');     $image->setimagecompressionquality(100);      file_put_contents('text-fill-example.png', $image); } catch(imagickexception $e){     error_log($e); } 

in above example, letters should contain dotted pattern. if open above svg code file in inkscape, pattern shows correctly. if embed svg code html shows pattern correctly in modern browsers.

the pattern ignored if try convert command line:

$ convert -verbose text-fill-example.svg text-fill-example.png  text-fill-example.svg svg 358x36 358x36+0+0 16-bit directclass 433b 0.020u 0:00.030 text-fill-example.svg=>text-fill-example.png svg 358x36 358x36+0+0 16-bit pseudoclass 256c 8.19kb 0.010u 0:00.009  $ convert --version version: imagemagick 6.7.7-10 2014-03-06 q16 http://www.imagemagick.org copyright: copyright (c) 1999-2012 imagemagick studio llc features: openmp     

does know this?

turns out svg code not entirely valid. used w3c validator end markup 100% valid , works:

<?xml version="1.0" encoding="utf-8"?> <!doctype svg public "-//w3c//dtd svg 1.1//en" "http://www.w3.org/graphics/svg/1.1/dtd/svg11.dtd"> <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" >     <defs>         <pattern id="mypattern" x="0" y="0" width="20" height="20" patternunits="userspaceonuse">             <rect width="20" height="20" fill="#ffffff" />              <circle cx="10" cy="10" r="5" stroke="#0000bb" fill="#dd8d8d" />          </pattern>     </defs>     <text y="100%"         stroke="#ff0000"         fill="url(#mypattern)"         font-size="40pt">         hello <tspan style="font-style: italic">svg</tspan> world!     </text> </svg> 

Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -