Unable to load base64 encoded JPEG2000 string in ImageMagick
Posted: 2018-12-08T08:03:24-07:00
Hello All,
I have just been introduced to ImageMagick - so please pardon my ignorance on this library.
Im trying to load the below string using ImageMagick - However no joy. Any help would be very much appreciated. Here is my sample code.
The error message is"The image cannot be displayed because it contains error" . The string that I have with me (base64encoded) is not something that I generated. It's a response that I get from an API call - So I'm assuming it to be valid jpeg2000 encoded string. I tried decoding it at convertstring.com/EncodeDecode/Base64Decode . I'm seeing plain text strings.. something like ... "Created by: JJ2000 version 4.1" .. So I'm guessing the string has some meta data that needs to be stripped off before it can work
I have just been introduced to ImageMagick - so please pardon my ignorance on this library.
Im trying to load the below string using ImageMagick - However no joy. Any help would be very much appreciated. Here is my sample code.
Code: Select all
$imagedata ="AAAADGpQICANCocKAAAAFGZ0eXBqcDIgAAAAAGpwMiAAAAAtanAyaAAAABZpaGRyAAAAyAAAAKAAAwcHAAAAAAAPY29scgEAAAAAABAAAAGXanAyY/9P/1EALwAAAAAAoAAAAMgAAAAAAAAAAAAAAKAAAADIAAAAAAAAAAAAAwcBAQcBAQcBAf9SAAwAAAABAQUEBAAA/1wAI0JvGG7qbupuvGcAZwBm4l9MX0xfZEgDSANIRU/ST9JPYf9kACIAAUNyZWF0ZWQgYnk6IEpKMjAwMCB2ZXJzaW9uIDQuMf+QAAoAAAAAAQMAAf9SAAwAAAABAQUEBAAA/5PPoKgT/dHUscn3uMJWDWKb153z8hPvSInB8QsdvHSg4pzoLevV6cHhwCOWrDWed1zB8RKHyC4PEhigx/MYuIx4wci8q/CEo2kiHBrV8DhszG7ymZ/UH7atm39cdbppgIDD4VYfCrB00E+GI+Qf3v1IHzVdC6k/pMRXolANASf+TQYCTKERfZoHB65rCU23EcMzjiQo+2MAmLli7aos4tyAgMOrw6tBVpk5rPA9rz1HB6Wn+siLUizMFl3TKpn7s1pJGcCba3pGnanMUNO8OP+EwaMdppACpwb6vbqSpeUbgICAgICAgID/2Q==";
// Decode image from base64
$image=base64_decode($imagedata);
// Create Imagick object
$im = new Imagick();
// Convert image into Imagick
$im->readimageblob($image);
// Create thumbnail max of 200x82
$im->thumbnailImage(200,82,true);
// Add a subtle border
$color=new ImagickPixel();
$color->setColor("rgb(220,220,220)");
$im->borderImage($color,1,1);
// Output the image
$output = $im->getimageblob();
$outputtype = $im->getFormat();
header('Content-type: image/jpeg');
echo $output;