我目前正在使用一個php gd實現來調整內存不斷耗盡的圖像 - 相當快。我想這個問題是PHP的功能,如imagecreatefromstring等使用php生成圖像縮略圖 - 內存不足
是否有一個簡單的實施調整圖像大小不使用此功能,所以我不會增加我的php.ini內存限制?
我目前正在使用一個php gd實現來調整內存不斷耗盡的圖像 - 相當快。我想這個問題是PHP的功能,如imagecreatefromstring等使用php生成圖像縮略圖 - 內存不足
是否有一個簡單的實施調整圖像大小不使用此功能,所以我不會增加我的php.ini內存限制?
GD不使用那麼多的內存,所以你在你的代碼中有其他問題。
如果您調整多個圖像的大小並且不在新創建的圖像上調用imagedestroy
,則會在內存泄漏中運行。
真彩色圖像可以用'寬×高×4×內存中的字節。 500萬像素圖像上的'createimagefromjpg'和20MB內存限制將立即耗盡所有內存。 – 2013-02-26 12:17:38
我知道,但PHP5.3中的默認內存限制是128M,這肯定適合。如果您的主機不支持合適的內存限制,並且不會爲您更換它,則應該尋找其他主機。 – Philipp 2013-02-26 12:28:24
這裏是你
function make_thumb($src, $dest, $desired_width,$desired_h) {
/* read the source image */
$source_image = imagecreatefromjpeg($src);
$width = imagesx($source_image);
$height = imagesy($source_image);
$desired_height = $desired_h;
/* create a new, "virtual" image */
$virtual_image = imagecreatetruecolor($desired_width, $desired_height);
/* copy source image at a resized size */
imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height);
/* create the physical thumbnail image to its destination */
imagejpeg($virtual_image, $dest);
}
PHP函數也許有在你的代碼中的內存泄漏,但誰在乎:)(我們展示代碼) – AmazingDreams 2013-02-26 12:05:47