2013-02-25 72 views
1

我越来越麻烦约imagick阅读SVG的文本,像这样:ImageMagick的失败文本的渲染,SVG文件

$xmlDoc = new DOMDocument(); 
$svgroot = $xmlDoc->createElement('svg'); 
$textnode = $xmlDoc->createElement('text'); 
$textnode->setAttribute('font-size','24'); 
$textnode->setAttribute('transform','matrix(3.1054,0,0,3.1054,158.5,0)'); 
$textnode->setAttribute('font-family','helvetica'); 
$textnode->appendChild($xmlDoc->createTextNode("eeee")); 

$textnode = $svgroot->appendChild($textnode); 
$xmlDoc->appendChild($svgroot); 

$svgtext = new Imagick(); 
$svgtext->setbackgroundcolor('#00000000'); 

$svgtext->readImageBlob($xmlDoc->saveXML()); 

将在最后一行readImageBlob函数抛出一个异常(“黑体”的字体已经安装在Windows /字体中)。 它说:

Uncaught exception 'ImagickException' with message 'must specify image size `C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/1/magick-270886DDFFPHkGTr' @ error/mvg.c/ReadMVGImage/185' in C:\xampp\htdocs\opencart\imagicktest.php:106 Stack trace: #0 C:\xampp\htdocs\opencart\imagicktest.php(106): Imagick->readimageblob('<?xml version="...') #1 {main} thrown in C:\xampp\htdocs\opencart\imagicktest.php on line 106 

这个bug只在Windows Server 2003中,当imageMagic在WinXP下运行不会抛出此异常。 我觉得这个bug是https://bugzilla.redhat.com/show_bug.cgi?id=193474

相似可能是windows2003需要安装的东西来支持imagick渲染SVG字体?

回答

-1

ImagickException抛出作为图像尺寸属性是从根svg元件缺失。不同版本的ImageMagick SVG系统库将为您的行为做出贡献。为了解决这个问题 - 只需指定与viewBoxx,& y属性的图像尺寸。

$xmlDoc = new DOMDocument(); 
$svgroot = $xmlDoc->createElement('svg'); 
$svgroot->setAttribute('viewBox','0 0 60 24'); // Set the viewable canvas 
$svgroot->setAttribute('x',0);     // Left offset 
$svgroot->setAttribute('y',16);    // Top offset 
$svgroot->setAttribute('width',60);   // Optional rendering width 
$svgroot->setAttribute('hieght',24);   // Optional rendering height 
+0

感谢您的帮助,当我设置宽度和高度时,错误已修复。但是,当textnode的setAttribute(“FONT-FAMILY”,“someFontsName”),文本将不会被渲染到cavans,当我删除字体家庭节点,文本会出现没有风格。可能是SVG系统库错误(我使用ImageMagick 6.8.3)?顺便说一下,如果svg有节点,图像也不能渲染。如何在windows2003下更改SVG系统库?我绝望...... – lizhi 2013-02-27 12:38:45

+0

字体家族应该在style属性中设置。参见[文本](http://www.w3.org/TR/SVG/text.html)和[字体](http://www.w3.org/TR/SVG/fonts.html)。即:'setAttribute('style','font-family:Helvetica,sans-serif;')'。对于windows2003下的系统库,[ServerFault](http://serverfault.com/)将是一个很好的开始。 – emcconville 2013-02-28 23:59:08