【问题标题】:Unable to use imagecopyresized in amazon ec2 linux server无法在亚马逊 ec2 linux 服务器中使用 imagecopyresized
【发布时间】:2018-06-26 18:20:10
【问题描述】:
  • 我正在尝试使用以下代码在 amazon linux 服务器上上传和调整图像大小。
  • 它在我的本地系统中运行良好。但不在服务器上。我收到服务器错误 500。
  • 错误只发生在这一行if(!imagecopyresized($new_image, $old_image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height)){return false;}

  • 我已经经历了很多不合适的解决方案,是否有任何选项或替代解决方案?

    function makeThumbnails($updir, $img, $id, $name, $extension, $MaxWe = 150, $MaxHe = 150) {
        ini_set ( "memory_limit", "48M");
        $arr_image_details = getimagesize($img);
    
        $width = $arr_image_details[0];
        $height = $arr_image_details[1];
        $percent = 100;
        if ($width > $MaxWe)
            $percent = floor(($MaxWe * 100) / $width);
    
        if (floor(($height * $percent) / 100) > $MaxHe)
            $percent = (($MaxHe * 100) / $height);
    
        if ($width > $height) {
            $newWidth = $MaxWe;
            $newHeight = round(($height * $percent) / 100);
        } else {
            $newWidth = round(($width * $percent) / 100);
            $newHeight = $MaxHe;
        }
    
        if ($arr_image_details[2] == 1) {
            $imgt = "ImageGIF";
            $imgcreatefrom = "ImageCreateFromGIF";
        }
        if ($arr_image_details[2] == 2) {
            $imgt = "ImageJPEG";
            $imgcreatefrom = "ImageCreateFromJPEG";
        }
        if ($arr_image_details[2] == 3) {
            $imgt = "ImagePNG";
            $imgcreatefrom = "ImageCreateFromPNG";
        }
        if ($imgt) {
            $old_image = $imgcreatefrom($img);
            $new_image = imagecreatetruecolor($newWidth, $newHeight);
    
            if ($arr_image_details[2] == 3) {
                imagealphablending($new_image, false);
                imagesavealpha($new_image, true);
            }
            if(!imagecopyresized($new_image, $old_image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height)){
                return false;
            }
            $imgt($new_image, $updir . "" . $name);
            return true;
      }
    

    }

【问题讨论】:

  • 你在日志中看到他们在说什么了吗?
  • 是的,“PHP 致命错误:调用未定义的函数 ImageCreateFromJPEG()”。但是GD已经存在了
  • 认为它不是用 libjpeg 编译的。 Postet 回答如何使用 libjpeg 安装 PHP。这就是为什么所有其他功能都有效但 ImageCreateFromJpeg 功能无效的原因

标签: php linux amazon-web-services amazon-ec2 php-gd


【解决方案1】:

看到你的失败后。我猜它不是用 libjpeg 编译的。对于 ImageCreateFromJPEG,您需要 gd 和 libjpeb。确保使用 --with-jpeg-dir 运行配置。您可能需要搜索它。我使用命令 find / -name libjpeg* 并获得了 CentOS5 的 /usr/lib。

PHP完整编译如下:

wget http://us1.php.net/distributions/php-5.5.10.tar.gz -O php.tar.gz
tar -xvf php.tar.gz
cd php-5.5.10
yum -y install libxml2-devel libmcrypt-devel libpng-devel
./configure --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d  --with-apxs2 --with-mysql --with-mysqli --with-zlib --with-curl --with-libdir=lib --with-openssl --with-pdo-mysql --with-mcrypt  --with-pcre-regex --enable-zip --with-gd --enable-mbstring --with-jpeg-dir=/usr/lib
make clean
make
make install

【讨论】:

    【解决方案2】:

    为php安装GD库

    sudo yum install php55-gd
    

    【讨论】:

      猜你喜欢
      • 2012-09-09
      • 1970-01-01
      • 2016-07-05
      • 2013-07-11
      • 2015-10-15
      • 2017-01-24
      • 2013-09-28
      • 1970-01-01
      • 2019-03-06
      相关资源
      最近更新 更多