Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 3200 bytes) inphp
$image_path = 'E:\www\01.jpg'; echo '1: ' . memory_get_usage() . '<br>'; $img1 = imagecreatefromjpeg($image_path); echo '2: ' . memory_get_usage() . '<br>'; $img2 = imagecreatetruecolor(800, 23277); echo '3: ' . memory_get_usage() . '<br>';
輸出以下:函數
1: 1117840code
2: 95350704圖片
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 3200 bytes) in E:\www\Demo.php on line 88內存
能夠看出,imagecreatefromjpeg用了94M內存,下面的imagecreatetruecolor也須要94M內存,二者加上就超過默認的128M了,因此,imagecreatetruecolor函數報錯,緣由在哪裏,由於這個圖片的高度實在過高了,23227個像素get
先獲取圖片的高度,若是高度大於10000,那就就設置php可用內存ini_set('memory_limit', '256M');it
$image_path = 'E:\www\01.jpg'; $image_info = getimagesize($image_path); if ($image_info[1] > 10000) { ini_set('memory_limit', '256M'); } echo '1: ' . memory_get_usage() . '<br>'; $img1 = imagecreatefromjpeg($image_path); echo '2: ' . memory_get_usage() . '<br>'; $img2 = imagecreatetruecolor(800, 23277); echo '3: ' . memory_get_usage() . '<br>';
輸出以下:im
1: 1120504error
2: 95353368img
3: 135840936