der_chirurg
der_chirurg

Reputation: 1535

PHP get image from byte[] out of a Database

I want to display an Image with a PHP-Script. I get the image data out of a Database. The data is a byte[]. Does anyone know how to do this?

I tried this yet:

function GetImage($imageDataArray)
{
   $base64String = "";
   for($i = 0; $i < count($imageDataArray); $i++)
   {
       $string = trim(strtr(base64_encode($imageDataArray[$i]), '+/', '-_'), '='); 
       $base64String .= $string;
   }

   return 'data:image/png;base64,' . $base64String ;
}

And call it here:

echo '<img src="'.$im->GetImage($imageDataArray).'" alt="Picture" />';

But I don't get an result. The picture is not shown.

Upvotes: 1

Views: 441

Answers (2)

Adam Bremen
Adam Bremen

Reputation: 695

get rid of base64_encode() && use urlencode() || rawurlencode()

Upvotes: 0

Kris
Kris

Reputation: 8868

This might help You Imagick::readImageBlob

Upvotes: 1

Related Questions