我有一个脚本可以根据上传的图像创建缩略图。它对 jpg 工作正常,但给我一个错误
致命错误:允许的内存大小 67108864 字节已耗尽(尝试分配 26250000 字节)
当我上传 png 图像时。
脚本是:
//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;
}
正如我所说,它与 JPG 和 GIF 完美配合。
该内存错误仅出现在 PNG 中,而且我只使用了 1.2Mb 的图像。
我该如何解决这个问题?
谢谢
帕特里克