2013-08-26 151 views
0

我試圖轉換由SVGGraph庫(http://www.goat1000.com/svggraph.php)創建的SVG圖像。Imagick將SVG轉換爲PNG - 將顏色替換爲黑色和白色

SVG在瀏覽器中着色(紅色,綠色,黃色,灰色......),一切都很好。但是當我轉換它時,它只是黑色和白色。

有了這個代碼,我把它轉換:

//new instance of imagick 
$im = new Imagick(); 
//read the svg file/data (its not saved on the filesystem) 
$im->readImageBlob($svgFile); 

$im->setImageFormat("png24"); 
$im->writeImage('cylinder.png'); 
$im->clear(); 
$im->destroy(); 

我曾與JPEG和PNG輸出格式嘗試過,但結果是一樣的,所有的顏色將與黑色

更換有沒有人有一個想法如何解決這個問題?

+0

我不熟悉SVGGraph但你檢查,看看是否SVG文件是100%有效?此外,請檢查http://stackoverflow.com/questions/4809194/convert-svg-image-to-png-with-php,它可能會給你的想法。 – Technoh

回答

0

試試這個方法:

$im = new Imagick(); 
$im->setBackgroundColor(new ImagickPixel('transparent')); 
$im->readImageBlob($svgFile); 

$im->setImageFormat("png24"); 
$im->writeImage('cylinder.png'); 
$im->clear(); 
$im->destroy() 
相關問題