IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Bibliothèques et frameworks PHP Discussion :

[GD] Redimensionnement


Sujet :

Bibliothèques et frameworks PHP

  1. #1
    Membre confirmé
    Homme Profil pro
    Inscrit en
    Août 2004
    Messages
    128
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Août 2004
    Messages : 128
    Par défaut [GD] Redimensionnement
    Bonjour à tous,
    voilà j'ai un soucis sur un problème pourtant classique à en jugé tout les renseignement que j'ai peu trouvé mais j'm'en sort pas quand même
    Donc : je veux redimmensionné(200x150) un jpeg uploadé, pour ce faire j'ai utilisé ce scrypt :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
     
    function thumbail($file, $maxWidth, $maxHeight){//Créer une image à partir de $file
        $img = ImageCreateFromJpeg("$file");
        //Dimensions de l'image
        $imgWidth = imagesx($img);
        $imgHeight = imagesy($img);
        //Facteur largeur/hauteur des dimensions max
        $whFact = $maxWidth/$maxHeight;
        //Facteur largeur/hauteur de l'original
        $imgWhFact = $imgWidth/$imgHeight;
        //fixe les dimensions du thumb
        if($whFact < $imgWhFact){//Si largeur déterminante
            $thumbWidth  = $maxWidth;
            $thumbHeight = $thumbWidth/$imgWhFact;
        } else { //Si hauteur déterminante
            $thumbHeight = $maxHeight;
            $thumbWidth = $thumbHeight*$imgWhFact;
        }
     
        //Crée le thumb (image réduite)
        $imgThumb = ImageCreateTruecolor($thumbWidth, $thumbHeight);
        //Insère l'image de base redimensionnée
        ImageCopyResized($imgThumb, $img, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight);
        //Nom du fichier thumb
        $imgThumbName = "thumb_".$file;
        //Crée le fichier thumb
        $fp = fopen($imgThumbName, "w");
        fclose($fp);
        //Renvoie le thumb créé
        ImageJpeg($imgThumb, $imgThumbName);
        return $imgThumbName;
    }
    que j'appel comme ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    move_uploaded_file( $_FILES['upload_img']['tmp_name'],$_SESSION['dir_img']."/".$_FILES['upload_img']['name']);
     
    chmod($_SESSION['dir_img']."/".$_FILES['upload_img']['name'],0777);
     
    $redimmensionned = thumbail($_SESSION['dir_img']."/".$_FILES['upload_img']['name'],200,150);
     
    copy($redimmensionned , $_SESSION['dir_img']."/".$_FILES['upload_img']['name']);
    le fichier est bien uploadé mais pas redimmensionné et j'obtient les erreure suivante :

    Warning: fopen(thumb_../FRONTOFFICE/1/img/1/Hiver.jpg): failed to open stream: No such file or directory in /home/pharmado/www/dev/BACKOFFICE/lst_img.php on line 34

    Warning: fclose(): supplied argument is not a valid stream resource in /home/pharmado/www/dev/BACKOFFICE/lst_img.php on line 35

    Warning: imagejpeg(): Unable to open 'thumb_../FRONTOFFICE/1/img/1/Hiver.jpg' for writing in /home/pharmado/www/dev/BACKOFFICE/lst_img.php on line 37

    Warning: copy(thumb_../FRONTOFFICE/1/img/1/Hiver.jpg): failed to open stream: No such file or directory in /home/pharmado/www/dev/BACKOFFICE/lst_img.php on line 52
    dois-je me battre avec mon administrateur serveur ? ^^
    bizzard que la copie(l'upload) de fichier passe et pas l'ouverture ...

    Pleeaaaaase Heeellp ^^

    merci d'avance

  2. #2
    Membre éprouvé
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    87
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Mars 2006
    Messages : 87
    Par défaut
    Salut


    Je crois que ton probleme est tout bete: quand on regarde les erreures ont vois que le nom du fichier que tu essaye de creer/ouvrir est "thumb_/repertoire_machin/repertoire_chose/nomDuFichierOriginal.jpg" tu voudrais pas plutot "/repertoire_machin/repertoire_chose/thumb_nomDuFichierOriginal.jpg"

    Je pense donc que le probleme c ton "$imgThumbName = "thumb_".$file; ".
    Puisque "$file" semble etre le chemin et non pas le nom du fichier

    En esperant avoir repondu a ta question

  3. #3
    Membre confirmé
    Homme Profil pro
    Inscrit en
    Août 2004
    Messages
    128
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Août 2004
    Messages : 128
    Par défaut
    GG Vince !!!

    après une petite retouche du scrypt :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
     
    function thumbail($path, $filename, $maxWidth, $maxHeight){//Créer une image à partir de $file
    	$file = $path.$filename;
        $img = ImageCreateFromJpeg("$file");
        //Dimensions de l'image
        $imgWidth = imagesx($img);
        $imgHeight = imagesy($img);
        //Facteur largeur/hauteur des dimensions max
        $whFact = $maxWidth/$maxHeight;
        //Facteur largeur/hauteur de l'original
        $imgWhFact = $imgWidth/$imgHeight;
        //fixe les dimensions du thumb
        if($whFact < $imgWhFact){//Si largeur déterminante
            $thumbWidth  = $maxWidth;
            $thumbHeight = $thumbWidth/$imgWhFact;
        } else { //Si hauteur déterminante
            $thumbHeight = $maxHeight;
            $thumbWidth = $thumbHeight*$imgWhFact;
        }
     
        //Crée le thumb (image réduite)
        $imgThumb = ImageCreateTruecolor($thumbWidth, $thumbHeight);
        //Insère l'image de base redimensionnée
        ImageCopyResized($imgThumb, $img, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight);
        //Nom du fichier thumb
        $imgThumbName = $path."thumb_".$filename;
        //Crée le fichier thumb
        $fp = fopen($imgThumbName, "w");
        fclose($fp);
        //Renvoie le thumb créé
        ImageJpeg($imgThumb, $imgThumbName);
        return $imgThumbName;
    }
    ça marche nickel
    Merci bcp

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Kylix] Fenêtres non redimensionnables
    Par fred78 dans le forum EDI
    Réponses: 2
    Dernier message: 01/12/2002, 14h08
  2. [VB6] [Interface] Redimensionnement automatique
    Par ychalan dans le forum VB 6 et antérieur
    Réponses: 7
    Dernier message: 30/09/2002, 18h32
  3. redimensionnement d'une JWindow
    Par mbp566 dans le forum Agents de placement/Fenêtres
    Réponses: 2
    Dernier message: 02/08/2002, 03h41
  4. Redimensionnement des Paquets IP sur un Réseau Local
    Par Bonoboo dans le forum Développement
    Réponses: 2
    Dernier message: 12/07/2002, 15h40
  5. Redimensionnement d'une surface
    Par Freakazoid dans le forum DirectX
    Réponses: 4
    Dernier message: 01/07/2002, 22h01

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo