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?
Figured out.
I had to remove the data:image/png;base64,
part from the posted string, and then imagick could interpret it as blob.
readImageBlob — Reads image from a binary string : http://php.net/manual/en/imagick.readimageblob.php
$base64 = "iVBORw0KGgoAAAAN....";
$imageBlob = base64_decode($base64);
$imagick = new Imagick();
$imagick->readImageBlob($imageBlob);
header("Content-Type: image/png");
echo $imagick;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With