File tree Expand file tree Collapse file tree 1 file changed +10
-7
lines changed
Expand file tree Collapse file tree 1 file changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -324,14 +324,14 @@ function echoAsPng(string $svg): void
324324 $ svg = preg_replace ('/(animation: fadein.*?;)/m ' , 'opacity: 1; ' , $ svg );
325325 $ svg = preg_replace ('/(animation: currentstreak.*?;)/m ' , 'font-size: 28px; ' , $ svg );
326326
327- // create canvas
328- $ imagick = new Imagick () ;
329- $ imagick -> setBackgroundColor ( new ImagickPixel ( ' transparent ' ) );
327+ // save SVG in a unique filename
328+ $ filename = md5 ( $ svg ) . " .svg " ;
329+ file_put_contents ( $ filename , ' <?xml version="1.0" encoding="UTF-8" standalone="no"?> ' . $ svg );
330330
331- // add svg image
332- $ imagick-> setFormat ( ' svg ' );
333- $ imagick ->readImageBlob ( ' <?xml version="1.0" encoding="UTF-8" standalone="no"?> ' . $ svg );
334- $ imagick ->setFormat ( ' png ' );
331+ // create Imagick object from SVG
332+ $ imagick = new Imagick ( $ filename );
333+ $ imagick ->setImageFormat ( " png " );
334+ $ imagick ->setBackgroundColor ( new ImagickPixel ( ' transparent ' ) );
335335
336336 // echo PNG data
337337 header ('Content-Type: image/png ' );
@@ -340,4 +340,7 @@ function echoAsPng(string $svg): void
340340 // clean up memory
341341 $ imagick ->clear ();
342342 $ imagick ->destroy ();
343+
344+ // delete temporary file
345+ unlink ($ filename );
343346}
You can’t perform that action at this time.
0 commit comments