Page 1 of 1
convert base64 tiff string to base64 gif string
Posted: 2013-11-20T04:21:00-07:00
by insomnix
This is ridiculous, but I'm running into an issue. I am receiving a base64 tiff string. No other option. The problem is I can't display a tiff image, so I need to change it to something I can use. I don't want to store an image on the server, so I want something created on the fly. Most likely this image will only ever need to be generated one time, so no need to cache it. The other problem is, I have to run command line from php. I have tried something like:
Code: Select all
$cmd = "convert 'inline:data:tiff;base64,".$image."' test.gif";
$dataurl = system($cmd);
where $image is the string. What I get is nothing. I am a novice when it comes to image magick, so any help is appreciated.
Re: convert base64 tiff string to base64 gif string
Posted: 2013-11-20T05:48:40-07:00
by Bonzo
You could try this:
Code: Select all
<?php
$cmd = "convert $image JPG:-";
header("Content-type: image/jpeg");
passthru($cmd, $retval);
?>
Re: convert base64 tiff string to base64 gif string
Posted: 2013-11-20T13:55:54-07:00
by insomnix
Ok, I tried that and I get nothing. On some of my try's I get an error, this example returned the same one. "The command line is too long."
Re: convert base64 tiff string to base64 gif string
Posted: 2013-11-20T14:20:53-07:00
by Bonzo
I would try and get the code working with something simple like a jpg and then move onto your tiff file.
Re: convert base64 tiff string to base64 gif string
Posted: 2013-11-21T04:41:41-07:00
by insomnix
I installed the dll for my test machine to see if I could get this to work using the php Imagick class. The below code is working great, but not every server I'm going to use this on will have the class. So I still need to work out how to do this same thing from command line.
Code: Select all
$imagedata= 'iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==';
// Decode image from base64
$image=base64_decode($imagedata);
// Create Imagick object
$im = new Imagick();
// Convert image into Imagick
$im->readimageblob($image);
$im->setImageFormat("png24");
$thumbnail = $im->getImageBlob();
echo '<img src=data:image/png;base64,'.base64_encode($thumbnail).' />';
Re: convert base64 tiff string to base64 gif string
Posted: 2013-11-21T05:43:38-07:00
by Bonzo
I have just disabled Imagick on my server as it will not work with php 5.4. I had an error every time someone viewed a php page on my website. The error files got very large quickly!