Imagick svg not showing

32 Views Asked by At

After an update (I suppose) is this simple script no longer working correctly. I have removed all unnecessary coding for testing and debugging but still unable to solve this issue.

I have a signature that looks like this

signature

Trying to convert it to a png, it worked for years, but since a couple of days it stopped working. The image is created with the correct dimensions, but there is no signature in the image/

$svg = <<<SVG
<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="76" height="130"><path fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" d="M 1 120 c 0.05 -0.14 1.61 -5.62 3 -8 c 3.16 -5.42 6.98 -10.7 11 -16 c 10.03 -13.21 20.14 -24.67 30 -38 c 8.64 -11.69 16.71 -23.19 24 -35 c 2.23 -3.62 3.67 -8 5 -12 c 0.62 -1.87 1.6 -4.79 1 -6 c -0.72 -1.43 -4.28 -4 -6 -4 c -2.34 0 -6.67 2.11 -9 4 c -4.19 3.39 -8.58 8.38 -12 13 c -3.12 4.21 -5.87 9.31 -8 14 c -1.09 2.4 -1.62 5.37 -2 8 c -0.27 1.92 -0.31 4.14 0 6 c 0.33 1.96 0.93 4.4 2 6 c 2.04 3.05 6.19 5.92 8 9 c 1.24 2.11 1.78 5.35 2 8 c 0.43 5.15 0.42 10.66 0 16 c -0.59 7.41 -1.24 14.97 -3 22 c -1.85 7.41 -8 22 -8 22"/></svg>
SVG;

$image = new Imagick();

$image->readImageBlob($svg);

$image->setImageFormat("png");

$canvas = new Imagick();
$canvas->newImage($image->getImageWidth(), $image->getImageHeight(), 'white');
$canvas->setImageFormat('png');

$canvas->compositeImage($image, Imagick::COMPOSITE_OVER, 0, 0);

$filePath = $folder.'/test.png'; // Voer het pad in waar je de afbeelding wilt opslaan
$canvas->writeImage($filePath);

// Opruimen
$image->clear();
$canvas->clear();
$image->destroy();
$canvas->destroy();

To debug I tested if this was working:

$svg = <<<SVG
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg">
    <rect x="10" y="10" width="80" height="80" fill="black" />
</svg>
SVG;

And that gave as expected:

square

Now tested with this:

$svg = <<<SVG
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="200" height="100">
    <path fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" d="M 10 50 L 190 50"/>
</svg>
SVG;

And once again an image with the correct dimensions but that visible line.

Any suggestions what the issue van be and how to solve this? Any help is very much appreciated.

2

There are 2 best solutions below

0
Danny '365CSI' Engelman On

Maar...

Your first image is the valid signature, why would you want to overlay that over another image?

<svg xmlns="http://www.w3.org/2000/svg" width="76" height="130">
    <path fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
        d="m1 120c.05-.14 1.61-5.62 3-8 3.16-5.42 6.98-10.7 11-16 10.03-13.21 20.14-24.67 30-38 8.64-11.69 16.71-23.19 24-35 2.23-3.62 3.67-8 5-12 .62-1.87 1.6-4.79 1-6-.72-1.43-4.28-4-6-4-2.34 0-6.67 2.11-9 4-4.19 3.39-8.58 8.38-12 13-3.12 4.21-5.87 9.31-8 14-1.09 2.4-1.62 5.37-2 8-.27 1.92-.31 4.14 0 6 .33 1.96.93 4.4 2 6 2.04 3.05 6.19 5.92 8 9 1.24 2.11 1.78 5.35 2 8 .43 5.15.42 10.66 0 16-.59 7.41-1.24 14.97-3 22-1.85 7.41-8 22-8 22" />
</svg>

PHP code

<?php

$svg = <<<SVG
<svg xmlns="http://www.w3.org/2000/svg" width="76" height="130">
    <path fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
        d="m1 120c.05-.14 1.61-5.62 3-8 3.16-5.42 6.98-10.7 11-16 10.03-13.21 20.14-24.67 30-38 8.64-11.69 16.71-23.19 24-35 2.23-3.62 3.67-8 5-12 .62-1.87 1.6-4.79 1-6-.72-1.43-4.28-4-6-4-2.34 0-6.67 2.11-9 4-4.19 3.39-8.58 8.38-12 13-3.12 4.21-5.87 9.31-8 14-1.09 2.4-1.62 5.37-2 8-.27 1.92-.31 4.14 0 6 .33 1.96.93 4.4 2 6 2.04 3.05 6.19 5.92 8 9 1.24 2.11 1.78 5.35 2 8 .43 5.15.42 10.66 0 16-.59 7.41-1.24 14.97-3 22-1.85 7.41-8 22-8 22" />
</svg>
SVG;

$image = new Imagick();
$image->readImageBlob($svg);
$image->setImageFormat("png");
$image->writeImage('signature.png');
$image->clear();
$image->destroy();

?>
0
Muiter On

My host converted back from version 7.1.1-29 to 7.1.1-27 and now it is working again. But still curious what point of the changelog might have caused this issue.

https://github.com/ImageMagick/Website/blob/main/ChangeLog.md