Question

I know that I can output an image using GD by using

 <img src='draw.php'>

Where draw.php is a file containing the code to create an image. How can I instead output the image via a function call (I am using the Zend Framework so will be using a View Helper) rather than simply pointing to a .php file in an img tag as above?

Any help greatly appreciated.

Was it helpful?

Solution

you can't.

at least not in a useable way - you could encode the image with base64:

<img src="data:image/png;base64,iVBORw0KGgoAAAANS..." alt=""/>

i don't have any idea which browsers support this, though ... quick test:

  • firefox: ok
  • chrome: ok
  • opera: ok
  • ie6: fail
  • ie7: fail
  • safari: fail

ok, forget it.

but, you're probably trying to do something different - passing the file through ZF. i can't help you with that, but it should work roughly like this:

in your controller, set the output type to image/png (however ZF handles that) pass through your image and make sure ZF doesn't add anything to the output (like additional html and stuff).

OTHER TIPS

Why not make your View Helper create an image, write it to disk, and then output/return the img tag with the correct source attribute?

Send appropriate headers (content type) and then use http://www.php.net/image_jpeg

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top