2017-10-18 65 views
0

我正在使用imagick將svg轉換爲png。但我的svg包含嵌入的圖像。所以在將其轉換爲png時不會呈現嵌入圖像。svg to png不能在php

$image = new \Imagick(); 
try{ 
    $file_name = uniqid($prefix).".jpeg"; 
    $image->readImageBlob($raw_svg); 
    $image->setImageFormat("png24"); 
    $image->writeImage("$folder_name/".$file_name); 
} catch (ImagickException $ex) { 
    echo $ex->getMessage(); 
} 

SVG數據

<?xml version="1.0" encoding="UTF-8" standalone="no" ?> 
<!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" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="600" height="400" viewBox="0 0 600 400" xml:space="preserve"> 
<desc>Created with Fabric.js 2.0.0-beta7</desc> 
<defs> 
</defs> 
<rect x="0" y="0" width="600" height="400" fill="#000000"></rect> 
    <g transform="translate(300.77 141.27) scale(2.45 2.26)"> 
     <text xml:space="preserve" font-family="Dollar2" font-size="22" font-style="normal" font-weight="normal" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(255,255,255); fill-rule: nonzero; opacity: 1; white-space: pre;" > 
      <tspan x="-117.34" y="6.91" >Back Side</tspan> 
     </text> 
    </g> 
<g transform="translate(289.57 247.98) scale(0.35 0.35)"> 
    <image xlink:href="data:image/png;base64,iVBORw0KGgoAAAANtTyE2NP5d9xZHM0bHtWwv3UYAuCINIplLWR8DS0uSOiTGLf1D2r/s3a8rxSbGLsVX4jt7nWc7JwHa/hqcyfVf6ZPmZ/u79nun+mTHHP6VX+t6lO+PckRyonYcOdqNETPJtLnBs89dwI0s7Y24alIM0g883zrzOP61/GnsT/6p607++djHcyJo6rcpFOQRCyjv8TYAAeI+bBrle9xgAAAABJRU5ErkJggg==" x="-334.5" y="-173.5" style="stroke: rgb(240,240,240); stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-opacity: 0; fill-rule: nonzero; opacity: 1;" width="669" height="347"></image> 
<rect x="-334.5" y="-173.5" width="669" height="347" style="stroke: rgb(240,240,240); stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: none; fill-rule: nonzero; opacity: 1;"/> 
</g> 
</svg> 

SVG Image SS
PNG IMAGE SS

+1

讓我知道如果缺少任何物品,我都試過,包括大部分的細節。 – DS9

+0

發佈的圖片數據似乎已損壞。 – ccprog

+0

爲了安全起見,許多SVG代表不會渲染'image xlink'標籤。請參閱[本答案](https://stackoverflow.com/a/29632564/438117)瞭解提示。 – emcconville

回答

0

以上內容改變以下後得到解決: PHP版本:5.5

的apt-get安裝php5- imagick
易於得到安裝實:graphicsmagick-ImageMagick的-COMPAT
易於得到安裝ImageMagick的
apt-get的安裝建立必要的檢查安裝& & apt-get的集結出發ImageMagick的-y

要添加自定義字體:
所有自定義字體(TTF文件)複製到以下位置:

在/ usr /共享/字體/ TrueType字體

然後

FC-緩存-v在/ usr /共享/字體