Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php ImageMagick/IMagick以SVGs偏移量渲染组_Php_Imagemagick_Imagick - Fatal编程技术网

Php ImageMagick/IMagick以SVGs偏移量渲染组

Php ImageMagick/IMagick以SVGs偏移量渲染组,php,imagemagick,imagick,Php,Imagemagick,Imagick,我有一个应用程序,它将SVG作为输入,并将其转换为PNG作为输出。我遇到了一个问题,如果SVG使用标记对项目进行了分组,则内容会在SVG上呈现到右侧和下方 这仅在使用IMagick时发生。如果我在Illustrator或Inkscape for PC中打开SVG,它看起来很好。以下是SVG代码的样子: <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="2400px" height="3200px" xmlns:xlin

我有一个应用程序,它将SVG作为输入,并将其转换为PNG作为输出。我遇到了一个问题,如果SVG使用标记对项目进行了分组,则内容会在SVG上呈现到右侧和下方

这仅在使用IMagick时发生。如果我在Illustrator或Inkscape for PC中打开SVG,它看起来很好。以下是SVG代码的样子:

<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="2400px" height="3200px" xmlns:xlink="http://www.w3.org/1999/xlink">
   <g id="SvgjsG1048" transform="rotate(0 1200 1600) translate(30.927835051559143 41.23711340207863) scale(0.9742268041237008 0.9742268041237009) " x="30.927835051559143" y="41.23711340207863">
      <image id="SvgjsImage1049" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="aerosmith.png" width="2400" height="3200"></image>
   </g>
</svg>
这里没有什么不寻常的事。删除设置分辨率的代码没有任何区别,我也尝试过重置页面,但没有效果

现在,如果我删除标记并将图像保留在那里,那么SVG渲染就没有问题了。但是,我无法控制应用程序是否发送分组项目,而IMagick需要渲染它,不管发生什么

以下是在SVG中使用标记渲染为PNG时的图像:

下面是is的外观:


Inkscape安装在服务器上,因此IMagick/ImageMagick正在使用它,因此我不确定从何处开始调试和修复此问题。任何帮助都将不胜感激

当您通过命令行ImageMagick工具(例如
convert test.svg test_output.png
)转换它时会发生什么?我不能使用命令行,因为这是一个web应用程序,我需要保留对对象的引用,以便使用它创建复合图像。我将JSON数据发布到应用程序中,它使用这些数据(包括SVG的链接)创建模型图像。如果我没有弄错的话,SVG也是默认的96 dpi,PNG需要在200 dpi时为2400x3200。所以我也有这个要求,我没有建议在应用程序中使用命令行。我说过,您需要测试命令行以准确确定问题的原因。大多数SVG代理库不允许
xlink
图像导入。这是在系统安全级别。修补并重新编译
rsvg
库,或者使用ImageMagick的内部
msvg:
引擎。
// setup the SVG
$svg_front = new Imagick();
$svg_front->setBackgroundColor(new ImagickPixel('transparent'));
$svg_front->readImage($json->imageFront); // pull in the SVG image

// convert the SVG to PNG @ 200 dpi - yes, it works!
$svg_front->setImageUnits(imagick::RESOLUTION_PIXELSPERINCH);
$svg_front->setImageResolution(200,200);

// set image format
$svg_front->setImageFormat('png');

// render the SVG
echo $svg_front;