• 技术文章 >后端开发 >php教程

    3.7兆的图片为何用不了imagecreatefromjpeg函数

    2016-06-13 11:21:59原创1019
    3.7兆的图片为什么用不了imagecreatefromjpeg函数
    图片上传生成缩略图,使用以下代码
    $imgsrc='//m.sbmmt.com/m/article/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时就会出现空白,后面的代码就不执行了。请问有没有什么办法解决此问题,或在上传时直接改变图片大小。


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

    ------解决方案--------------------
    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.
    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    上一篇:php写XML文件编码异常,求解答 下一篇:自己动手写 PHP MVC 框架(40节精讲/巨细/新人进阶必看)

    相关文章推荐

    • PHP网站常见一些安全漏洞及防御方法• PHP Hyperf 3.0 发布!新功能速览• 详解PHP怎么实现旋转图片验证• 简单理解PHP超级全局变量• 一起聊聊PHP的路由与伪静态应用
    1/1

    PHP中文网