图片上传生成缩略图,使用以下代码
$imgsrc='E:/123.jpg';
$w1 = getimagesize($imgsrc);  
     $src =imagecreatefromjpeg(imgsrc);// imagecreatefromjpeg($imgsrc);
$dst = ImageCreateTrueColor($x,$y);  
ImageCopyResampled($dst,$src,0,0,0,0,$x,$y,$w1[0],$w1[1]); 
imagejpeg($dst,$imgsrc,80);

当图片小于2M时是好用的,没问题。但是我上传了一个3.7兆的图片时,程序走到imagecreatefromjpeg时就会出现空白,后面的代码就不执行了。请问有没有什么办法解决此问题,或在上传时直接改变图片大小。

解决方案 »

  1.   

    内存不足了吧?
    决定 GD 是否能够正常运行的条件,不在于图片文件的大小,而在于图片的点阵数
    GD 在处理图片时会先将图片在内存中按每像素8个字节的规模展开成位图
      

  2.   

    It's an out-of-memory issue.  I don't know if there's a formula, but it seems to happen with images that are large or high-resolution.  Changing the memory in php.ini might work, up to a point.  After trying 768MB I gave up and use ImageMagick now.please try use code ini_set('memory_limit','768MB') before process image.
      

  3.   


    需要8字节么,请教一下,我的理解是24bit/3字节,32bit/4字节,剩下的字节是用于解霍夫曼么?