2017-08-16 110 views
1

我试图上传图像(没有问题),如有必要(旋转图像)(无问题)然后重新调整大小(即出现问题时)。 一旦图像已被旋转,我使用imagecreatefromjpeg功能时出现以下错误:致命错误:调整图像大小时允许的内存大小已耗尽

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 9288 bytes). 

这里是我的代码

<?php 
$path='uploads/test7.jpg'; 

$exif = exif_read_data($path); 
if (!empty($exif['Orientation'])) 
{ 
    $imageResource = imagecreatefromjpeg($path); 
    switch ($exif['Orientation']) { 
     case 3: 
     $image = imagerotate($imageResource, 180, 0); 
     break; 
     case 6: 
     $image = imagerotate($imageResource, -90, 0); 
     break; 
     case 8: 
     $image = imagerotate($imageResource, 90, 0); 
     break; 
     default: 
     $image = $imageResource; 
    } 
} 

imagejpeg($image, $path,100); 

$newImage= imagecreatefromjpeg($path); //this line generates an error 
?> 
+1

内存限制似乎设置为128M,要么增加它,要么限制文件上传大小。 – localheinz

回答

0

您已经提到的错误你:

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 9288 bytes).

这意味着您的内存限制是太低。尝试使用ini_set('memory_limit, '256M')自己增加它,请求管理员增加限制或升级您的托管软件包。

您可以在PHP manual - Resource limits中查看更多信息。

0

非常感谢您的帮助,对于迟到的回复感到抱歉。 我最终通过在创建新图像之前使用imagedestroy解决了我的问题。

相关问题