Error when using readImageBlob

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
cyriltra
Posts: 1
Joined: 2013-05-09T00:51:00-07:00
Authentication code: 6789

Error when using readImageBlob

Post by cyriltra »

Hello,

I'm creating a image using HTML canvas and I upload it into a php script. However, if the image dimensions are too big, I got the following error message:
"Zero size image string passed". But I'm not sure what is the limitation... How can I increase the max image width and height if this is the issue ?

Here is my code:

1) Convert the canvas to a data string (javascript code)

Code: Select all

var dataURL = canvas.toDataURL({format:"jpeg", quality:0}),
strDataURI = dataURL.substr(dataURL.indexOf(',')+1);
then I upload the data using jquery $.post()

2) My PHP script to receive the image string and create the file

Code: Select all

$data = base64_decode($_POST["data"]);

$folder   = "images/";
$filename = uniqid(rand(), true);
$ext      = ".jpg";
$filepath = $folder.$filename.$ext;

$image = new Imagick();
$image->setCompression(Imagick::COMPRESSION_JPEG);
$image->setCompressionQuality(90);
$image->setFormat('jpg');
  
if($image->readImageBlob($data)) {

  $image->setImageFormat('jpg');
  $image->writeImage($filepath);
  $image->clear();
  $image->destroy(); 
     
  // Do stuff with $filepath
}

I'm using imagick (3.1.0RC2 ) with image magick (6.6.0-4)

Thank you for your help
Post Reply