PHP | imagedestroy() Function Last Updated : 29 Jan, 2020 Comments Improve Suggest changes Like Article Like Report The imagedestroy() function is an inbuilt function in PHP which is used to destroy an image and frees any memory associated with the image. Syntax: bool imagedestroy( resource $image ) Parameters: This function accepts a single parameter $image which holds the name of image. Return Value: This function returns TRUE on success and FALSE on failure. Below examples illustrate the imagedestroy() function in PHP: Example 1: Destroying image after using it. php <?php // Load the png image $im = imagecreatefrompng( 'https://media.geeksforgeeks.org/wp-content/uploads/20200123135210/geeksforgeeksinverted.png'); // Crop the image $cropped = imagecropauto($im, IMG_CROP_BLACK); // Convert it to a png file header('Content-type: image/png'); imagepng($cropped); // Destroy the cropped image to deallocate the memory imagedestroy($cropped); ?> Output: $cropped variable is destroy by the end line and you can't access it after that line. Example 2: Checking if the variable is destroyed. php <?php // Load the png image $im = imagecreatefrompng( 'https://media.geeksforgeeks.org/wp-content/uploads/20200123135210/geeksforgeeksinverted.png'); header('Content-type: image/png'); // Destroy the image to deallocate the memory imagedestroy($im); // Try to access the destroyed variable imagepng($im); ?> Output: PHP log will give a error as the variable is destroyed. PHP Warning: imagepng(): supplied resource is not a valid Image resource. Reference: https://www.php.net/manual/en/function.imagedestroy.php Comment More infoAdvertise with us Next Article PHP | imagedestroy() Function gurrrung Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-Imagick Similar Reads PHP | imagesy() Function The imagesy() function is an inbuilt function in PHP which is used to return the height of the given image. Syntax: int imagesy( $image ) Parameters: This function accepts single parameters $image which is mandatory. This $image variable store the image created by imagecreatetruecolor() image creati 1 min read PHP | imagestring() Function The imagestring() function is an inbuilt function in PHP which is used to draw the string horizontally. This function draws the string at given position. Syntax: bool imagestring( $image, $font, $x, $y, $string, $color ) Parameters: This function accepts six parameters as mentioned above and describ 2 min read PHP | imagecopy() Function The imagecopy() function is an inbuilt function in PHP which is used to copy the image or part of image. This function returns true on success or false on failure. Syntax: bool imagecopy ( $dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h ) Parameters: This function accepts eigh 2 min read PHP | imagecrop() Function The imagecrop() function is an inbuilt function in PHP which is used to crop an image to the given rectangle. This function crops an image to the given rectangular area and returns the resulting image. The given image is not modified. Syntax: resource imagecrop ( $image, $rect ) Parameters: This fun 1 min read PHP | imagesx() Function The imagesx() function is an inbuilt function in PHP which is used to return the width of the given image. Syntax: int imagesx( $image ) Parameters: This function accepts single parameters $image which is mandatory. This $image variable can store the image created by imagecreatetruecolor() image cre 1 min read PHP | imagegd() function The imagegd() function is an inbuilt function in PHP which is used to output GD image to browser or file. This is most useful to convert any other image type to gd. imagecreatefromgd() function can be used to further read gd images. Syntax: bool imagegd( resource $image, float $to) Parameters:This 2 min read PHP | imageresolution() Function The imageresolution() function is an inbuilt function in PHP which is used to set and return the resolution of an image in DPI (dots per inch). If none of the optional parameters is given, the current resolution is returned as an indexed array. If one of the optional parameters is given it will set 2 min read PHP | imagetypes() Function The imagetypes() function is an inbuilt function in PHP which is used to return the image types supported by the PHP inbuilt installed library. Syntax: int imagetypes( void ) Parameters: This function does not accept any parameter. Return Value: This function returns the bit-field corresponding to t 1 min read PHP | imagegd2() Function The imagegd2() function is an inbuilt function in PHP which is used to output GD2 image to browser or file. This is most useful to convert any other image type to gd2. The imagecreatefromgd2() function can be used to further read gd2 images. Syntax: bool imagegd2( resource $image, float $to, int $ch 2 min read PHP | imagecreate() Function The imagecreate() function is an inbuilt function in PHP which is used to create a new image. This function returns the blank image of given size. In general imagecreatetruecolor() function is used instead of imagecreate() function because imagecreatetruecolor() function creates high quality images. 2 min read Like