php imagick - read image from base64

Viewed 16244

I am manipulating images with js, and I'd like to save these transformed images. I'm posting this data with ajax:

image : canvas.toDataURL('image/jpeg')

This way, I get the base64 code for the image, but I can't find a way to read it with Imagick.

This is my process:

$img = new Imagick();
$decoded = base64_decode($_POST['image']);
$img->readimageblob($decoded);

But this fails:

Fatal error: Uncaught exception 'ImagickException' with message 'no decode delegate for this image format `' @ error/blob.c/BlobToImage/360' in /Library/WebServer/Documents/test/save.php:7 Stack trace:

#0 /Library/WebServer/Documents/test/save.php(7): Imagick->readimageblob('u?Z?f?{??z?????...')

Any ideas why?

3 Answers
Related