Redimensionnement d'image

Résolu
cs_Batman60 Messages postés 71 Date d'inscription samedi 21 mai 2005 Statut Membre Dernière intervention 21 octobre 2007 - 21 oct. 2007 à 19:02
cs_Batman60 Messages postés 71 Date d'inscription samedi 21 mai 2005 Statut Membre Dernière intervention 21 octobre 2007 - 21 oct. 2007 à 20:12
bonsoir
je galère avec un script de redimensionnement d'image ,j'ai une erreur php du genre:
Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 10700 bytes) in C:\wamp\www\photo_upload\ajout_photo.php on line 32
en plus , l'envoi de photo sur mon site hébergé chez free avec le même script php ,de chez moi ca fonctionne à merveille mais chez d'autre personne ca ne marche pas,il y a la même erreur comme ci-dessus
c'est pour ca que je l'ai testé sur wamp pour voir
je n'y comprend plus rien  au secours
voici mon code:
<?php
session_start();
  if (isset($_FILES['choix_photo']) AND isset($_POST['nom_photo'])) // Si les variables existent
  {
    if ($_FILES['choix_photo'] != NULL AND $_POST['nom_photo'] != NULL) // Si on a quelque chose à enregistrer
    {
  $_photo= "photos/".$_POST['nom_photo'].".JPG";
  $_photo_mini= "photos/mini_".$_POST['nom_photo'].".jpg";
  $_extension_valide= array("JPG","jpg");
  $_extension_upload= substr(strrchr($_FILES['choix_photo']['name'],'.'),1);
  $_ip= $_SERVER['REMOTE_ADDR'];  
       if(is_file($_photo) == FALSE
           AND  in_array($_extension_upload,$_extension_valide))
       {
       move_uploaded_file($_FILES['choix_photo']['tmp_name'],$_photo);      
//-------------redim_image----------------------------------
$percent = 0.27;
$percent2 = 0.36;
$percent_mini = 0.05;
// Calcul des nouvelles dimensions
list($width, $height) = getimagesize($_photo);
$new_width = $width * $percent;
$new_height = $height * $percent;
$new_width2 = $width * $percent2;
$new_height2 = $height * $percent2;
$new_width_mini = $width * $percent_mini;
$new_height_mini = $height * $percent_mini;
// Redimensionnement
if(($width>2048 AND $height>1536) OR ($width>1536 AND $height>2048))
{
$_destination = imagecreatetruecolor($new_width, $new_height); //photo vide
$_source = imagecreatefromjpeg($_photo); // photo source  <- ligne 32 de l'erreur
imagecopyresampled($_destination, $_source, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
// Affichage
imagejpeg($_destination, $_photo, 100);
imagedestroy($_source);
//---------image mini-------------------
$_destination_mini = imagecreatetruecolor($new_width_mini, $new_height_mini);//photo vide
$_source_mini = imagecreatefromjpeg($_photo);//photo source
imagecopyresampled($_destination_mini, $_source_mini, 0, 0, 0, 0, $new_width_mini, $new_height_mini, $new_width, $new_height);
// Affichage
imagejpeg($_destination_mini, $_photo_mini, 100);
imagedestroy($_source_mini);
//----------------------------------------------------------                    
     else
  {
  $_destination  = imagecreatetruecolor($new_width2, $new_height2);
  $_source = imagecreatefromjpeg($_photo);
  imagecopyresampled($_destination, $_source, 0, 0, 0, 0, $new_width2, $new_height2, $width, $height);
  // Affichage
  imagejpeg($_destination, $_photo, 100);
  imagedestroy($_source);
//---------image mini----------------------
  $_destination_mini = imagecreatetruecolor($new_width_mini, $new_height_mini);
  $_source_mini = imagecreatefromjpeg($_photo);
  imagecopyresampled($_destination_mini, $_source_mini, 0, 0, 0, 0, $new_width_mini, $new_height_mini, $new_width2, $new_height2);
  // Affichage
  imagejpeg($_destination_mini, $_photo_mini, 100);   
  imagedestroy($_source_mini);
//----------------------------------------------------------                       
    }                                                                 
       }else{header('location:info_redim_image.php'); exit;}                                                                                            
    }
  }
if($_FILES['choix_photo'] == NULL)
{header('location:info_redim_image.php'); exit;}   
header('location:photos_parents.php');
exit;
?>

2 réponses

malalam Messages postés 10839 Date d'inscription lundi 24 février 2003 Statut Membre Dernière intervention 2 mars 2010 25
21 oct. 2007 à 19:22
Hello,

le script n'est pas en faute. C'est la taille de l'image qui l'est : elle est trop grosse, et demande donc à PHP bcp de mémoire pour la travailler. Et il n'y en a pas assez de paramétrée dans le php.ini de ton serveur web.
3
cs_Batman60 Messages postés 71 Date d'inscription samedi 21 mai 2005 Statut Membre Dernière intervention 21 octobre 2007
21 oct. 2007 à 20:12
merci pour la réponse
est-ce que l'on peut l'augmenter la mémoire
jusqu'a combien et comment
sur wamp par exemple
est-ce qu'il faut simplement modifier cette ligne la dans phph.ini:
memory_limit = 8M      ; Maximum amount of memory a script may consume (8MB)
0
Rejoignez-nous