PHp-调整PNG图像大小时出现内存错误 [英] PHp - memory error when resizing a PNG image
本文介绍了PHp-调整PNG图像大小时出现内存错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个脚本,可以从上传的图像中创建缩略图.可以与jpgs配合使用,但会给我一个错误
I have a script that creates a thumbnail out of an uploaded image. it works fine with jpgs, but gives me an error
致命错误:允许的内存大小已用完67108864字节(尝试分配26250000字节)
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 26250000 bytes)
当我上传png图片时.
when I upload a png image.
脚本为:
//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的图像.
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
推荐答案
在脚本前使用ini_set('memory_limit', '256M');
.
这篇关于PHp-调整PNG图像大小时出现内存错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文