0

I have a script that creates an image. I have to make a common format like GIF, JPEG or PNG out of it and convert it to base 64, later on.

When doing this, I do not want to save the image on the server, nor I want any browser output. So imagepng() seems not right command for this.

Any ideas?

hm.
  • 166
  • 9
  • Duplicate: http://stackoverflow.com/questions/35879/base64-encoding-image – Supericy Feb 06 '13 at 02:03
  • I do not need to load an image. The Image is drawn by a PHP script using JSON data. – hm. Feb 06 '13 at 02:12
  • you should note while this is possible, the last i checked internet explorer didn't care much for it. – Joshua Burns Feb 06 '13 at 02:25
  • I use the signature pad script, which uses canvas and falls back to flash canvas. It generates JSON in a hidden field which will be used to draw the image on the server side. ( http://thomasjbradley.ca/lab/signature-pad/ ) – hm. Feb 06 '13 at 17:15

1 Answers1

3

If all else fails, you can always do this:

ob_start();
imagepng($resource);
$png = base64_encode(ob_get_clean());
Matthew
  • 47,584
  • 11
  • 86
  • 98
  • Interesting method. I am a little scared to use this, because my script will rund inside of a content management system. – hm. Feb 06 '13 at 02:17
  • I tried it. It works. It seems to be the only way to do this. – hm. Feb 06 '13 at 17:13