convert base64 tiff string to base64 gif string

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
insomnix
Posts: 3
Joined: 2013-11-20T04:09:47-07:00
Authentication code: 6789

convert base64 tiff string to base64 gif string

Post 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.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: convert base64 tiff string to base64 gif string

Post by Bonzo »

You could try this:

Code: Select all

<?php 

$cmd = "convert $image JPG:-"; 

header("Content-type: image/jpeg"); 
passthru($cmd, $retval); 
?> 
insomnix
Posts: 3
Joined: 2013-11-20T04:09:47-07:00
Authentication code: 6789

Re: convert base64 tiff string to base64 gif string

Post 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."
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: convert base64 tiff string to base64 gif string

Post by Bonzo »

I would try and get the code working with something simple like a jpg and then move onto your tiff file.
insomnix
Posts: 3
Joined: 2013-11-20T04:09:47-07:00
Authentication code: 6789

Re: convert base64 tiff string to base64 gif string

Post 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).' />';
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: convert base64 tiff string to base64 gif string

Post 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!
Post Reply