Unable to load base64 encoded JPEG2000 string in ImageMagick

Refresh

December 2018

Views

63 time

1

Im trying to load the below string using ImageMagick - However no joy. Any help would be very much appreciated. Here is my sample code.

AAAADGpQICANCocKAAAAFGZ0eXBqcDIgAAAAAGpwMiAAAAAtanAyaAAAABZpaGRyAAAAyAAAAKAAAwcHAAAAAAAPY29scgEAAAAAABAAAAGZanAyY/9P/1EALwAAAAAAoAAAAMgAAAAAAAAAAAAAAKAAAADIAAAAAAAAAAAAAwcBAQcBAQcBAf9SAAwAAAABAQUEBAAA/1wAI0JvGG7qbupuvGcAZwBm4l9MX0xfZEgDSANIRU/ST9JPYf9kACIAAUNyZWF0ZWQgYnk6IEpKMjAwMCB2ZXJzaW9uIDQuMf+QAAoAAAAAAQUAAf9SAAwAAAABAQUEBAAA/5PH0GAbC7jcgs2kmdEMUXBOTe0ZP3eG31ljbR/B8Q8dhpBSootdqdIOwUNQ63bD5SIeMolPq8zeNPjwafrBTEzEdcfOSg+EuD4SwCjVW+CI0kMtAh6cF91DuZV5Jhz9ofvr3MQNhNJbFgCOdemuQcf0Wt7ARgAkmjWAw+FaDqMCqEsHliu62jOnmcT30J9iT6PW1CnZsjkg35ge3m0iENGtuclkHidMfxsJkbJH0o5FPrWAgMOqQ6qAmVjTwkHmBA26Mpk40mlXYZ92tOahRgXyYwOkfsYQM9vYIRAsrhVOuCCAgICAgICAgP/Z


$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);

// Decide the type of image file that you need
$im->setImageFormat('jpeg');

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

1 answers

0

Here's the working code..

$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);

// Decide the type of image file that you need
$im->setImageFormat('jpeg');

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