2015-09-06 145 views
0

我得到的平方而不是文本我在SVG输入:ImageMagick的转换SVG至PNG与错误的字体

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> 
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="200px" height="200px" version="1.1" 
viewBox="0 0 200 200" xmlns:xlink="http://www.w3.org/1999/xlink"> 

<text font-size="40px" x="0" y="50" font-family="Arial" > 
      123456789 ABCDEFGH 
</text> 

</svg> 

然后我就用这个代码convet为PNG对PHP:

<?php 
header('Content-Type: image/png'); 
$output = shell_exec("convert -size 280x280 test.svg png:- "); 
echo $output; 
?> 

和我得到这些方块,而不是我输入的文字:

enter image description here

任何ID eas如何控制这些字体?

我找到了一个链接,显示的字体很大的控制,但我不能 准确地了解他们是如何做: http://www.rubblewebs.co.uk/imagemagick/server/fonts.php

+1

我读ImageMagick的不完全能够SVG转换成别的东西。但是github上有一个工具。 https://github.com/shakiba/svgexport –

+0

谢谢@CharlotteDunois,但我需要它在PHP中funciton。我想从客户端浏览器隐藏SVG。我会使用CANVAS ... –

+0

那么,您已经在使用'shell_exec()'来执行命令行,为什么不使用svgexport呢? –

回答

0

首先,检查你正在运行的ImageMagick的版本升级,如果它是老 - 现在世界在网络上快速移动!

identify -version 
Version: ImageMagick 6.9.1-10 Q16 x86_64 2015-09-04 http://www.imagemagick.org 

其次,考虑使用rsvg委托 - 你可以列出代表这样的:

identify -list delegate | grep svg 
    cdr =>   "uniconvertor" "%i" "%o.svg"; mv "%o.svg" "%o" 
    cgm =>   "uniconvertor" "%i" "%o.svg"; mv "%o.svg" "%o" 
    dot =>   "dot" -Tsvg "%i" -o "%o" 
    dxf =>   "uniconvertor" "%i" "%o.svg"; mv "%o.svg" "%o" 
    fig =>   "uniconvertor" "%i" "%o.svg"; mv "%o.svg" "%o" 
    svg =>   "rsvg-convert" -o "%o" "%i" 

第三,检查哪些字体您已经安装了,是这样的:

identify -list font 

    Font: Arial 
    family: Arial 
    style: Undefined 
    stretch: Undefined 
    weight: 0 
    glyphs: /Library/Fonts/Microsoft/Arial.ttf 
    Font: ArialB 
    family: Arial 
    style: Undefined 
    stretch: Undefined 
    weight: 0 
    glyphs: /Library/Fonts/Microsoft/Arial Bold.ttf 

最后,如果你在我的系统上运行你的命令,你会得到这个 - 我已经添加了一个黑色的边框,所以你可以看到范围。

enter image description here