Skip to content

Commit 9ba9d10

Browse files
authored
Revert "Get imagick image from file instead of blob (#166)" (#167)
1 parent 1ef6384 commit 9ba9d10

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/card.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -324,23 +324,20 @@ 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-
// 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);
330-
331-
// create Imagick object from SVG
332-
$imagick = new Imagick($filename);
333-
$imagick->setImageFormat("png");
327+
// create canvas
328+
$imagick = new Imagick();
334329
$imagick->setBackgroundColor(new ImagickPixel('transparent'));
335330

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');
335+
336336
// echo PNG data
337337
header('Content-Type: image/png');
338338
echo $imagick->getImageBlob();
339339

340340
// clean up memory
341341
$imagick->clear();
342342
$imagick->destroy();
343-
344-
// delete temporary file
345-
unlink($filename);
346343
}

0 commit comments

Comments
 (0)