WideImage 1.0 branch (discontinued)

WideImage Wiki : HandleOwnership

MainPage :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register
Support This Project SourceForge.net Logo
Important notice: the development of WideImage 1.0 branch is discontinued. Please visit http://wideimage.sourceforge.net for the new version of library and documentation.
This web site will remain accessible to serve as documentation for the old versions of the library. For help on migration, please refer to the migration guide.

Handle ownership

By default, every image object owns its handle (which is a gd resource). By owning it, it's also responsible for destroying it properly. This is implemented via PHP's destructors -- when an image object is destroyed, it will automatically call imagedestroy() on its image handle. This means you don't have to destroy the images explicitly, they're destroyed when an image object is no longer used.

Example

$img = wiImage::load(...);

// get the handle
$handle = $img->getHandle();

// handle is valid
imagepng($handle);

// destroy the object
unset($img);

// handle isn't valid anymore
imagepng($handle);


Releasing a handle

Sometimes this behaviour is unwanted. When you want to have the control of the image resource even after the object is destroyed, you have to explicitly tell the object to release it:
$img = wiImage::load(...);

// get the handle
$handle = $img->getHandle();

// tell the object to release the handle
$img->releaseHandle();

// destroy the object
unset($img);

// handle is still valid
imagepng($handle);


But now you have to explicitly destroy the image resource. It's the price you pay.
imagedestroy($handle);



CategoryDoc

There are no comments on this page. [Add comment]

WideImage - an Object-Oriented PHP Image Library for Image manipulation
Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by Wikka Wakka Wiki 1.1.6.2
Page was generated in 0.0561 seconds