0

trying to read out a base64-encoded jpg, resize it and convert it back to base64.

$imgData = '[base64-string]';
$im = imagecreatefromstring(base64_decode($imgData));
// do resize stuff
$imgData = base64_encode(file_get_contents($im));
echo '<IMG SRC="data:image/jpeg;base64,' . $imgData . '">';

decoding works, encoding again based on image handler does not.

what am I doing wrong?

Martin
  • 22,212
  • 11
  • 70
  • 132
PDeS
  • 1
  • 1
  • 1
    `$im` isn't a file, it's an image resource. I don't think you can use `file_get_contents` on it like that. You probably need to do `imagepng` first on it. – ceejayoz May 16 '17 at 12:34
  • is there no way to do this based on the img resource? is there no way to do this without ouputting it first? – PDeS May 16 '17 at 12:36
  • You can output it to `php://temp` http://php.net/manual/en/wrappers.php.php – ceejayoz May 16 '17 at 12:40
  • i did not find the other post - thx for pointing me towards it. output buffering can indeed help to output it without having to actually create a file. THX! - both – PDeS May 16 '17 at 12:48

0 Answers0