1

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.

der_chirurg
  • 1,475
  • 2
  • 16
  • 26

2 Answers2

1

This might help You Imagick::readImageBlob

Kris
  • 8,680
  • 4
  • 39
  • 67
0

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

robert
  • 33,242
  • 8
  • 53
  • 74
Adam Bremen
  • 685
  • 1
  • 7
  • 18
  • @Ummar: I think with urlencode() it doesn't run. I think, the base64_encode() is wrong, because I get a String like this: _data:image/png;base64,MTM3ODANzgNzEMTMMTAMjYMTAMAMAMAMTMNzMNzINjgODIMAMAMAMTI4MAMAMAMTI4OANgMAMAMAMTk1NjIOTcM..._ I tried the same in ASP.NET MVC. I didn't have any problems there and the base64 string is different. – der_chirurg Jun 05 '12 at 12:28