如何使用 imagedestroy() 函数销毁 PHP 中的图像?
imagedestroy()是一个内置的PHP函数,用于销毁图像并释放与图像相关的任何内存。
语法
bool imagedestroy(resource $image)
参数
imagedestroy()只接受一个参数,$image。它包含图像的名称。
返回值
imagedestroy()成功时返回true,失败时返回false。
示例1-加载后销毁图像。
输出结果Note − By using imagedestroy() function, we have destroyed the $cropped variable and therefore, it can no longer be accessed.
说明-在示例1中,imagecreatefrompng()从本地驱动器文件夹加载图像并使用imagecropauto()函数从给定图像中裁剪图像的一部分。裁剪后,imagedestroy()函数用于销毁图像。销毁图像后,我们无法访问图像或$cropped变量。
示例2
注意-在上面的PHP代码中,使用该imagecreatetruecolor()函数创建了一个50×50的图像。创建图像后,imagedestroy()函数用于释放或释放已使用的内存。