简体   繁体   中英

Outputting image using php GD library via function call

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.

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).

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM