开发者

PHp - memory error when resizing a PNG image

I have a script that creates a thumbnail out of an uploaded image. it works fine with jpgs, but gives me an error

Fatal error: Allowed memory size of 67108864 bytes exhausted (tried开发者_高级运维 to allocate 26250000 bytes)

when I upload a png image.

The script is:

//create thumbnail; $modwidth and height are calculated in another part of the script
//$original is the path to the full sized image

$tn = imagecreatetruecolor($modwidth, $modheight); 
switch (strrchr($new_image_name,'.')) {
  case ".jpg":
    $image = imagecreatefromjpeg($original);
    break;
  case ".jpeg":
    $image = imagecreatefromjpeg($original);
    break;
  case ".png":
    $image = imagecreatefrompng($original);
    break;
  case ".gif":
    $image = imagecreatefromgif($original);
    break;
}
imagecopyresampled($tn, $image, 0, 0, $x_pos, $y_pos, $modwidth, $modheight, $width, $height); 
switch (strrchr($new_image_name,'.')) {
  case ".jpg":
    imagejpeg($tn, $target_path, 100);
    break;
  case ".jpeg":
    imagejpeg($tn, $target_path, 100);
    break;
  case ".png":
    imagepng($tn, $target_path, 0);
    break;
  case ".gif":
    imagegif($tn, $target_path);
    break;
}

As I said it works perfectly with JPGs and also with GIFs. That memory error appears only with PNGs, and I have only used a 1.2Mb image.

How can i solve this? thanks Patrick


Use ini_set('memory_limit', '256M'); before script.


You need to increase memory_limit setting in php.ini to something like this

memory_limit = 128M
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜