我试图用一个XLink的SVG文件转换空白图像:HREF的图像内使用下面的命令ImageMagick的:ImageMagick的转换SVG文件导致
convert file.png result.png
但是这给了我一个空白PNG文件,我相信问题来自图像,因为其他指令显示在png文件中。我可以得到它的工作通过使用命令:
convert msvg:file.svg result.png
是否有人知道如何使这项工作没有“msvg:”一部分?因为我必须在php-Imagick之后执行此操作,并且无法在我的php代码中添加“msvg:”。
SVG文件:
<?xml version="1.0"?>
<svg id="svg" width="1024" height="1024" preserveAspectRatio="xMinYMin">
<image id="svg-image" x="0" y="0" width="1024" height="1024" product_id="4" xlink:href="coeur.png">
</image>
<rect x="10" y="10" width="80" height="80" fill="red"/>
</svg>
ImageMagick的版本:6.7.7.10-5 + deb7u3
的 “转换格式-list | grep的SVG” 输出:
MSVG SVG rw+ ImageMagick's own SVG internal renderer
SVG SVG rw+ Scalable Vector Graphics (RSVG 2.36.1)
SVGZ SVG rw+ Compressed Scalable Vector Graphics (RSVG 2.36.1)
PHP代码:
$im = new Imagick();
$draw = new ImagickDraw();
$im->readImageBlob($svgParse->asXML());
$im->setImagePage(0, 0, 0, 0);
$im->scaleImage($viewBox['2'],$viewBox['3'], false);
foreach($ListText as $text){
$draw->setFont(Mage::getBaseDir('media').DS.'font'.DS.$text['font-family'].".ttf");
$draw->setFontSize($text['font-size']);
$draw->setFillColor ($text['fill']);
$im->annotateImage($draw, $text['x'], $text['y'], 0, $text['text']);
}
/*png settings*/
$im->setImageFormat("png32");
// FB image
$imFB = clone $im;
$imFB->resizeImage(1200,630,Imagick::FILTER_LANCZOS,1);
$imFB->writeImage($filename_FB);
$imFB->clear();
$imFB->destroy();
// TW image
$imTW = clone $im;
$imTW->resizeImage(280,150,Imagick::FILTER_LANCZOS,1);
$imTW->writeImage($filename_TW);
$imTW->clear();
$imTW->destroy();
$im->writeImage($filename);/*(or .jpg)*/
$im->clear();
$im->destroy();
之前,你能不能也发表您当前的PHP代码? – erjiang
我将我的PHP代码添加到了我的帖子中,因为它太长了评论 – JigokuArch
为了安全起见,rsvg委托没有加载外部图像资源。在用'$ img-> setFormat('MSVG')读取blob日期之前尝试设置MSVG格式;' – emcconville