2017-03-03 5 views
0

내가 Imagick과 JPG를 만들려고 해요와 BLOB 이미지를 읽기하지만 그것은 말한다 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 = '<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로 정의? $chart이 올바른지 여부를 확인하기 위해 무엇을 어떻게해야합니까?

문제는 BLOB

+0

'Imagick-> readImageBlob'이 ** 이진 데이터가 ** http://php.net/manual/en/imagick.readimageblob.php가 –

+0

그래서, $ 차트에 포함 된 기대 : 나는 바이너리를 읽을이 만든 a svg, 어떻게 그것을 읽을 수 Imagick 그것을 처리 할 수 ​​있습니까? – pmirnd

+0

[PHP Imagick을 사용하여 주어진 크기의 SVG를 읽는 법?] (http://stackoverflow.com/questions/9226232/how-to-read-an-svg-with-a-given-size- using-php-imagick) –

답변

0

음에 SVG로 변환하지,의 Blob을 읽고, 나는 SVG 파일로 readImageBlob을 사용했다.

//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...