2017-03-03 2 views
0

Je suis en train de créer un jpg avec Imagick mais j'ai une erreur dans readImageBlob(PHP) La lecture d'une image blob avec Imagick

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

Il dit:

négatif ou nul taille de l'image `/tmp/magick-29893mIHq2qQrLKKP '@ error/image.c/SetImageExtent/2601

Pointant vers la ligne que j'ai mentionnée précédemment. Je l'ai déjà défini $chart comme:

$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>'; 

Peut-être un problème avec la façon dont est défini $chart? Quoi et comment dois-je rechercher $chart afin de voir si est défini correctement ou non?

Le problème est en train de lire un Blob, pas la conversion d'un svg à un blob

+0

'Imagick-> readImageBlob' données binaires ** attend ** http://php.net/manual/en/imagick.readimageblob.php –

+0

Ainsi, le graphique $ contient un svg, comment le gérer avec Imagick pour le lire? – pmirnd

+0

Copie possible de [Comment lire un SVG avec une taille donnée en utilisant PHP Imagick?] (Http://stackoverflow.com/questions/9226232/how-to-read-an-svg-with-a-given-size- using-php-imagick) –

Répondre

0

Eh bien, j'utilisais readImageBlob avec un fichier svg. Je l'ai fait lire un fichier binaire:

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