1- <?php declare (strict_types = 1 );
1+ <?php
2+
3+ declare (strict_types=1 );
24
35/**
46 * Convert date from Y-M-D to more human-readable format
@@ -295,7 +297,8 @@ function generateErrorCard(string $message, array $params = null): string
295297 *
296298 * @param string $svg The SVG for the card to display
297299 */
298- function echoAsSvg (string $ svg ): void {
300+ function echoAsSvg (string $ svg ): void
301+ {
299302 // set content type to SVG image
300303 header ("Content-Type: image/svg+xml " );
301304
@@ -310,10 +313,11 @@ function echoAsSvg(string $svg): void {
310313 *
311314 * @throws ImagickException
312315 */
313- function echoAsPng (string $ svg ): void {
316+ function echoAsPng (string $ svg ): void
317+ {
314318 // trim off all whitespaces to make it a valid SVG string
315319 $ svg = trim ($ svg );
316-
320+
317321 // remove style and animations
318322 $ svg = preg_replace ('/(<style>\X*<\/style>)/m ' , '' , $ svg );
319323 $ svg = preg_replace ('/(opacity: 0;)/m ' , 'opacity: 1; ' , $ svg );
@@ -325,7 +329,7 @@ function echoAsPng(string $svg): void {
325329 $ imagick ->setBackgroundColor (new ImagickPixel ('transparent ' ));
326330
327331 // add svg image
328- $ imagick ->readImageBlob ($ svg );
332+ $ imagick ->readImageBlob (' <?xml version="1.0" encoding="UTF-8" standalone="no"?> ' . $ svg );
329333 $ imagick ->setImageFormat ('png ' );
330334
331335 // echo PNG data
0 commit comments