1
  • I am trying to upload and re-size images on amazon linux server with the below code.
  • It works fine in my local system. But not on server. I get Server error 500.
  • Error occurs only on this line 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;
      }
    

    }

miken32
  • 42,008
  • 16
  • 111
  • 154
  • Did you look in the log's what they are saying? – Kordi Mar 02 '16 at 09:16
  • Yes, "PHP Fatal error: Call to undefined function ImageCreateFromJPEG()". But GD is there already – Manikandan K Mar 02 '16 at 11:36
  • think its not compiled with libjpeg. Postet an answer how to install PHP with libjpeg. Thats why all other function works but not the ImageCreateFromJpeg Function – Kordi Mar 02 '16 at 12:09

2 Answers2

1

After seeing your failure. My Guess it that it's not compiled with libjpeg. For ImageCreateFromJPEG you need gd and libjpeb. Make sure to run configure with --with-jpeg-dir. You may have to search for it. I used the command find / -name libjpeg* and got /usr/lib for CentOS5.

Complete compilation of PHP is as follows:

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
Kordi
  • 2,405
  • 1
  • 14
  • 13
0

Install the GD library for php

sudo yum install php55-gd
Rayiez
  • 1,420
  • 19
  • 20