简体   繁体   English

(PHP)使用Imagick读取斑点图像

[英](PHP) Reading a blob image with Imagick

I'm trying to create an jpg with Imagick but I have an error in readImageBlob 我正在尝试使用Imagick创建jpg,但是readImageBlob出现错误

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

It says: 它说:

negative or zero image size `/tmp/magick-29893mIHq2qQrLKKP' @ error/image.c/SetImageExtent/2601 负或零图像大小`/ tmp / magick-29893mIHq2qQrLKKP'@ error / image.c / SetImageExtent / 2601

Pointing to the line that I mentioned before. 指向我之前提到的那一行。 I have previously defined $chart as: 我之前将$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>';

Could be a problem with how is $chart defined? $chart定义方式可能有问题? What and how should I look for $chart in order to see if is correct defined or not? 我应该怎样寻找$chart才能确定定义是否正确?

The problem is reading a Blob, not converting a svg to a blob 问题是读取Blob,而不是将svg转换为Blob

Well, I was using readImageBlob with a svg file. 好吧,我正在将readImageBlob与svg文件一起使用。 I made this to read a binary: 我这样做是为了读取二进制文件:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM