开发者

Does an image created with GD have a temporary path before its saved

I'm trying to create an image with GD then use that image with a class that requires I have the path to the image t开发者_如何学Goo access it. But I won't need the image again; so I am trying to not save it to the server first.

Does an image created with GD and PHP have a temporary path before you save it with something like imagegif()?


No there is no disk access until a function like imagegif() is called. The image is created in memory.

If the disk access is really hurting you i see two options. If not I'd just write out the image to a temp directory.

  • You could create a ramdisk (in memory file system) and write the files there
  • Also you could use the vfs:// stream wrapper that would also write into a virtual file system

But both those options only make sense if the added IO would hurt you badly


No, the images just exist in memory up until they're saved.

If the image is small enough you might consider sending it inline as a data: URI. This allows you to say <img src="data:,..." /> and have the data right there in the HTML output.

See e.g. http://www.websiteoptimization.com/speed/tweak/inline-images/

This doesn't prevent the need to write the image to file, but it does at least mean you can discard the temporary file as soon as it has been processed. If you serve it as a normal image file you then have to have some sort of cleanup process to remove files once they're no longer required, since the HTTP request for the image could come after the HTTP request for the original PHP file has long since completed.


No, the image exists only in memory. You can access it with the provided GD functions, but it doesn't exist on disk.


From php.net

imagegif — Output image to browser or file

What if you output your image to the browser i.s.o. a file? Wouldn't that be faster - assuming that speed is what want to accomplish.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜