Imagick 无法正确渲染 svg 不透明度
我需要 Inkscape 和 Imagick 的相同输出。
这是从 Inkscape 导出的预期结果。
但是,下面的 PHP 代码输出以下错误结果。
PHP 代码:
<?php
$im = new Imagick();
$im->setResolution(400,400);
$im->setBackgroundColor(new ImagickPixel('transparent'));
$im->readImageBlob(str_replace(array("color1", "color2"), array("yellow", "blue"), file_get_contents("img.svg")));
$im->setImageFormat("png");
header("Content-type: image/png");
echo $im;
?>
SVG 代码:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="400" height="400">
<rect width="100%" height="100%" fill="green" />
<path d="M250 150 L150 350 L350 350 Z" opacity="0.9" fill="color1" />
<path d="M150 50 L50 250 L250 250 Z" opacity="0.9" fill="color2" />
</svg>
I need same output from Inkscape and Imagick.
This is the expected result, exported from Inkscape.
However, the PHP code below outputs the following faulty result.
PHP code:
<?php
$im = new Imagick();
$im->setResolution(400,400);
$im->setBackgroundColor(new ImagickPixel('transparent'));
$im->readImageBlob(str_replace(array("color1", "color2"), array("yellow", "blue"), file_get_contents("img.svg")));
$im->setImageFormat("png");
header("Content-type: image/png");
echo $im;
?>
SVG code:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="400" height="400">
<rect width="100%" height="100%" fill="green" />
<path d="M250 150 L150 350 L350 350 Z" opacity="0.9" fill="color1" />
<path d="M150 50 L50 250 L250 250 Z" opacity="0.9" fill="color2" />
</svg>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当前版本的 Imagick 中已修复此问题。
This is already fixed in current version of Imagick.
Inkscape 使用并非普遍支持的
opacity
属性。请改用fill-opacity
和lines-opacity
。Inkscape uses the not ubiquitously supported
opacity
property. Usefill-opacity
andstroke-opacity
instead.您运行的是哪个版本的 PHP 和 ImageMagick?请分享
phpinfo()
的相关输出。 此 ImageMagick 错误会影响您吗?或者,如果您没有及时更新,其他 ImageMagic 错误是否会影响您?编辑:我目前无法轻松访问安装了 PHP ImageMagick 库的服务器,但如果我找到一个,我将测试提供的代码并发布我的结果。
编辑2:看起来像其他有同样的问题,除非该论坛帖子也是您的...
根据 此论坛帖子,您可以尝试:
一个人报告有效,但另一个人说无效...
What version of PHP and ImageMagick are you running? Please share the relevant output of
phpinfo()
. Could this ImageMagick bug be affecting you? Or if you're not up to date, could another ImageMagic bug be affecting you?EDIT: I don't have easy access to a server with PHP's ImageMagick libraries installed at the moment, but if I find one, I'll test the code provided and post my results.
EDIT2: Looks like others have the same issue, unless that forum post was also yours...
According to this forum post, you could try:
One person reported that worked, but another said it did not...