【发布时间】:2021-12-11 18:44:30
【问题描述】:
在为 php8 编译和安装 imagick(并解决导致发生的问题)之后,我现在可以将 svgs 转换为图像。但是,在安装了 inkscape 并检查了 imagick 的委托后,imagick 并没有检测和使用inkscape。没有任何进一步的错误需要解决,并且在浏览了大量的谷歌页面之后,我确信我要么错过了应该安装或配置的东西,要么我明显做错了什么。我将不胜感激任何指示和/或帮助。
您将在下面找到有关版本、代码和配置的信息,如果需要其他任何信息,请询问,我很乐意提供。
使用convert -list format | grep SVG grepping SVG 渲染器为我提供了 3 个基本渲染器(MSVG、SVG 和 SVGZ)。
用于渲染最终图像的 php 代码非常基础,不应该与手头的问题相关,但无论如何:
class SvgRenderer
{
private static ?Crop $_crop = null;
private static Imagick $_im;
// ...
public static function stringToPng32($svg)
{
self::$_im = new Imagick();
self::$_im->setFont('../fonts/arial.ttf');
self::$_im->readImageBlob($svg);
self::$_im->setImageFormat('png32');
if(self::$_crop !== null) self::_applyCrop();
return self::$_im->getImageBlob();
}
// ...
}
php、inkscape、imagick的版本分别是:
PHP:8.0.9
Inkscape:0.92.2
Imagick:7.1.0-0
svg 委托规则:
<delegate decode="svg" command=""@RSVGDecodeDelegate@" -o "%o" "%i""/>
<!-- Change export-filename to export-png for inkscape < 1.0 -->
<delegate decode="svg:decode" stealth="True" command=""@SVGDecodeDelegate@" "%s" --export-png="%s" --export-dpi="%s" --export-background="%s" --export-background-opacity="%s" > "%s" 2>&1"/>
第一张图片使用 imagick 和 inkscape 在本地渲染,第二张图片在运行完全相同代码的服务器上渲染。
【问题讨论】: