2017-03-03 69 views
0

我試圖創建Imagick的JPG一個團塊圖像,但我有readImageBlob(PHP)讀與Imagick

$image = new \Imagick(); 
$chart = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . $chart; 
$image->readImageBlob($chart); 
$image->setImageFormat("jpeg"); 

它說的錯誤:

負或零圖像大小`/tmp/magick-29893mIHq2qQrLKKP'@ error/image.c/SetImageExtent/2601

指向我之前提到的那一行。我已經定義$chart爲:

$chart = '<svg xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" class="highcharts-root" style="font-family:"lucida grande", "lucida sans unicode", arial, helvetica, sans-serif;font-size:12px;" xmlns="http://... (ETC) ...g></svg>'; 

可能是與如何定義$chart一個問題嗎? 什麼,以及如何查找$chart以查看是否正確定義?

的問題是閱讀的Blob,一個SVG不轉換到BLOB

+0

'Imagick-> readImageBlob'預計**的二進制數據** http://php.net/manual/en/imagick.readimageblob.php –

+0

所以,$圖表包含如何處理它然後與Imagick閱讀它? – pmirnd

+0

[如何使用PHP Imagick讀取給定大小的SVG?](http://stackoverflow.com/questions/9226232/how-to-read-an-svg-with-a-given-size-使用-php-imagick) –

回答

0

好,我是用readImageBlob用SVG文件。我提出這個閱讀二進制:

//Set 2 temp files, one for the svg that I'll make and another one for the image that I will use later 
$filesvg = '/tmp/chart.svg'; 
$chartImage = '/tmp/tempchartimg.jpg'; 

//the svg had to use that header 
$chart = '<?xml version="1.0" encoding="UTF-8" standalone="no" ?>' . $chart; 

//I'll save the svg in the temp file made before 
file_put_contents($filesvg,$chart); 
//Coverting and save in as 'binaryImage' file the svg to jpg 
$binaryImage = shell_exec("convert $filesvg jpg:-"); 

//The the usal Imagick part: 
$image = new \Imagick(); 

//Now I can read a binary file 
$image->readImageBlob($binaryImage); 
$image->setImageFormat("jpg"); 
$image->setImageCompressionQuality(90); 
$image->resizeImage(600, 400, \imagick::FILTER_LANCZOS, 1); 
$image->writeImage($chartImage); 

//rest of my code...