我使用單個圖像上傳/裁剪/調整大小腳本文件高達10MB。PHP內存限制25MB用盡 - 文件上傳/裁剪/調整大小
測試時,我將php_ini內存限制設置爲25M,上傳文件時僅用了1.4MB左右。
"Allowed memory size of 26214400 bytes exhausted (tried to allocate 10368 bytes)"
這對我來說很奇怪,是不是10368 < 26214400? (修辭問題)
或者這是否意味着我超過25MB 10368字節?我的腳本應該使用這麼多的內存嗎?
代碼:
function make_thumbnails($updir, $img)
{
$thumbnail_width = 200;
$thumbnail_height = 150;
$thumb_preword = "thumb_";
$arr_image_details = GetImageSize($updir.$img);
$original_width = $arr_image_details[0];
$original_height = $arr_image_details[1];
if($original_width > $original_height){
$new_width = $thumbnail_width;
$new_height = intval($original_height*$new_width/$original_width);
} else {
$new_height = $thumbnail_height;
$new_width = intval($original_width*$new_height/$original_height);
}
$dest_x = intval(($thumbnail_width - $new_width)/2);
$dest_y = intval(($thumbnail_height - $new_height)/2);
if($arr_image_details[2]==1) { $imgt = "ImageGIF"; $imgcreatefrom = "ImageCreateFromGIF"; }
if($arr_image_details[2]==2) { $imgt = "ImageJPEG"; $imgcreatefrom = "ImageCreateFromJPEG"; }
if($arr_image_details[2]==3) { $imgt = "ImagePNG"; $imgcreatefrom = "ImageCreateFromPNG"; }
if($imgt)
{
$old_image = $imgcreatefrom($updir.$img);
$new_image = imagecreatetruecolor($thumbnail_width, $thumbnail_height);
imageCopyResized($new_image,$old_image,$dest_x,
$dest_y,0,0,$new_width,$new_height,$original_width,$original_height);
$imgt($new_image,$updir.$thumb_preword.$img);
// Added by your suggestions:
imagedestroy($old_image);
imagedestroy($new_image);
}
}
您剛剛嘗試分配另一個10368字節時達到了內存限制。請向我們展示一些代碼,以便我們可以幫助您。 – Gumbo 2009-11-14 18:12:38
感謝您的參與,代碼已發佈 – 2009-11-14 18:20:08
真的很難確定最佳答案,總體而言,您都回答了我正在尋找的內容。謝謝!! – 2009-11-14 18:36:55