Précédent   Forum des professionnels en informatique > PHP > Bibliothèques et frameworks > Images > GD
GD Forum d'entraide pour l'extension GD permettant de manipuler des images en PHP. Avant de poster -> tutoriels GD
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 29/03/2006, 17h48   #1
En attente de confirmation mail
 
Inscription : août 2004
Messages : 122
Détails du profil
Informations forums :
Inscription : août 2004
Messages : 122
Points : 32
Points : 32
Envoyer un message via MSN à clemsouz
Par défaut 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 :
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 :
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 :

Citation:
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
clemsouz est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/03/2006, 09h10   #2
Membre régulier
 
Avatar de vincedom
 
Inscription : mars 2006
Messages : 87
Détails du profil
Informations personnelles :
Âge : 29
Localisation : France, Paris (Île de France)

Informations forums :
Inscription : mars 2006
Messages : 87
Points : 98
Points : 98
Envoyer un message via MSN à vincedom Envoyer un message via Skype™ à vincedom
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
vincedom est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/03/2006, 09h53   #3
En attente de confirmation mail
 
Inscription : août 2004
Messages : 122
Détails du profil
Informations forums :
Inscription : août 2004
Messages : 122
Points : 32
Points : 32
Envoyer un message via MSN à clemsouz
GG Vince !!!

après une petite retouche du scrypt :
Code :
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
clemsouz est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 22h57.


 
 
 
 
Partenaires

Hébergement Web