Imagick svg 未显示

问题描述 投票:0回答:1

更新后(我想)这个简单的脚本不再正常工作。我已经删除了所有不必要的测试和调试代码,但仍然无法解决这个问题。

我有一个看起来像这样的签名

尝试将其转换为 png,它工作了好几年,但几天后它就停止工作了。该图像是使用正确的尺寸创建的,但图像中没有签名/

$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();

为了调试,我测试了这是否有效:

$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;

这正如预期的那样:

现在用这个进行测试:

$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;

再次获得尺寸正确但线条可见的图像。

有什么建议以及如何解决这个问题吗?非常感谢任何帮助。

svg imagick jsignature
1个回答
0
投票

玛尔...

您的第一张图像是有效签名,为什么要将其覆盖在另一个图像上?

<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 代码

<?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();

?>
© www.soinside.com 2019 - 2024. All rights reserved.