2016-03-02 1 views
1
  • J'essaye de télécharger et de redimensionner des images sur le serveur Linux d'amazon avec le code ci-dessous.
  • Cela fonctionne très bien dans mon système local. Mais pas sur le serveur. Je reçois une erreur de serveur 500.
  • erreur se produit uniquement sur cette ligne if(!imagecopyresized($new_image, $old_image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height)){return false;}Impossible d'utiliser imagecopyresized dans amazon ec2 linux server

  • Je suis passé par une abondance de rien solution fits, est-il une option ou autre correctif cela?

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

    }

+0

Avez-vous cherché dans ce qu'ils sont le journal de dire? – Kordi

+0

Oui, "Erreur fatale PHP: appel à la fonction indéfinie ImageCreateFromJPEG()". Mais GD est là déjà –

+0

pense qu'il n'est pas compilé avec libjpeg. Postet une réponse comment installer PHP avec libjpeg. C'est pourquoi toutes les autres fonctions fonctionnent mais pas la fonction ImageCreateFromJpeg – Kordi

Répondre

1

Après avoir vu votre échec. My Devinez que ce n'est pas compilé avec libjpeg. Pour ImageCreateFromJPEG, vous avez besoin de gd et de libjpeb. Assurez-vous d'exécuter configure avec --with-jpeg-dir. Vous devrez peut-être le chercher. J'ai utilisé la commande find/-name libjpeg * et j'ai obtenu/usr/lib pour CentOS5.

compilation complète de PHP est comme suit:

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 
+0

Merci, cette astuce le fait pour moi. –