PHP: imagedestroy - Manual

downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

imageellipse imagedashedline

Last updated: Fri, 26 Jan 2007

view this page in

# imagedestroy

(PHP 3, PHP 4, PHP 5)

imagedestroy -- Destroy an image

## Описание

bool imagedestroy ( resource image )

imagedestroy() frees any memory associated with image `image`.

## Список параметров

`image`

  An image resource, returned by one of the image creation functions, such as imagecreatetruecolor().

## Возвращаемые значения

Возвращает `TRUE` в случае успешного завершения или `FALSE` в случае возникновения ошибки.

add a note User Contributed Notes
imagedestroy
Docey
20-Oct-2006 10:59
`When the script stop PHP will automatic destory ANY
resources, this goes for aswell for images, thus in the
case the use clicks the stop button, php will automatic
clear the resource.
thus imagedestroy is used to clear the memory BEFORE
the script ends. this is usefull to keep memory usage
DURING the script to an acceptable level.
hope this clear somethings up.`
roland at more-pc dot nl
24-Sep-2005 06:31
`As Andrew states below, it's IMPERATIVE that you use the imagedestroy() function. But your script may abort before it reaches the call to imagedestroy() (for example the user may click the browsers 'stop' button). In this case the default PHP behaviour is to abort the script, never reaching your call to imagedestroy().
One way of doing it (the one which works very well for me) is with register_shutdown_function():
<?
function shutdown_func() {
global $img;
if($img)
imagedestroy($img);
}
register_shutdown_function("shutdown_func");
$img = imagecreate...(...);
... // manipulate image
// normally I'd need the following line, but now it's handled by shutdown_func()
// imagedestroy($img);
?>`
Andrew Hoffmann - ahoffmann at wisc dot edu
23-Jun-2005 07:25
`When working with a lot of high-resolution images, it's IMPERATIVE that you use the imagedestroy() function.
In my scenario, I was taking two high resolution desktop wallpapers and shrinking them down into successively smaller ones (preventing the user from having to upload a dozen files).
At first, my script would run, then just stop. I realized later that I had not destroyed the source image and the newly resized image in memory after I had finished writing the file out to disk. Thus, I quickly reached the memory limit that my hosting provider placed in their php.ini file.
Reusing an image variable does NOT clear the old data out of memory! You must use imagedestroy() to clear the data out. (I don't know if unset() works as well).
Also note that the image data in memory is raw, so don't base how much memory you are using based on the original filesize of the compressed image (such as jpeg or png).`
dan at mlodecki dot net
04-Mar-2004 04:42
`I have noticed that gd drawing functions can behave oddly if there is a previous image which has not been imagedestroy()'ed. You should always imagedestroy when you are done with an image object.`
add a note
imageellipse imagedashedline

Last updated: Fri, 26 Jan 2007
show source | credits | stats | sitemap | contact | advertising | mirror sites
Copyright © 2001-2007 The PHP Group
All rights reserved.
This mirror generously provided by: Yahoo! Inc.
Last updated: Sat Mar 10 09:32:46 2007 PST