简体   繁体   English

无法在Amazon EC2 Linux服务器中使用ImageCopyResize

[英]Unable to use imagecopyresized in amazon ec2 linux server

  • I am trying to upload and re-size images on amazon linux server with the below code. 我正在尝试使用以下代码在Amazon Linux服务器上上传图像并调整其大小。
  • It works fine in my local system. 它在我的本地系统中运行良好。 But not on server. 但不在服务器上。 I get Server error 500. 我收到服务器错误500。
  • Error occurs only on this line if(!imagecopyresized($new_image, $old_image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height)){return false;} 仅在以下行发生错误if(!imagecopyresized($new_image, $old_image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height)){return false;}

  • I've gone through a plenty of solution nothing fits, is there any option or alternative fix this? 我已经经历了很多不适合的解决方案,是否有任何选择或替代解决方案?

     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; } 

    } }

After seeing your failure. 看到你的失败之后。 My Guess it that it's not compiled with libjpeg. 我猜这不是用libjpeg编译的。 For ImageCreateFromJPEG you need gd and libjpeb. 对于ImageCreateFromJPEG,您需要gd和libjpeb。 Make sure to run configure with --with-jpeg-dir. 确保使用--with-jpeg-dir运行configure。 You may have to search for it. 您可能需要搜索。 I used the command find / -name libjpeg* and got /usr/lib for CentOS5. 我使用命令find / -name libjpeg *并为CentOS5获得了/ usr / lib。

Complete compilation of PHP is as follows: 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

安装php的GD库

sudo yum install php55-gd

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM