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] Problème de format PNG avec imagepng


Sujet :

Bibliothèques et frameworks PHP

  1. #1
    Nouveau membre du Club
    Femme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2009
    Messages
    30
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2009
    Messages : 30
    Points : 36
    Points
    36
    Par défaut [GD] Problème de format PNG avec imagepng
    Bonjour,

    Problème avec:
    -imagejpeg() ;
    -imagecreatefromjpeg().

    En m'aidant des sites, je n'arrive pas à corriger mes erreurs, un avis de l'extérieur serais un plus ^^

    Voici mon code:

    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
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
       //###########################################################
    	//# -Génère la miniature de l'image dans le sous-répertoire #
    	//###########################################################
    	// Génère la miniature de l'image dans le sous-répertoire 'miniature' si elle n'existe pas déjà
    	function genere_miniature($Nom_Dossier_Miniature) 
    	{
    		// Calcul du ratio entre la grande image et la miniature
    		$taille_max = 100;
    		if ($this->getLargeur() <= $this->getHauteur()) 
    		{
    			$ratio = $this->getHauteur() / $taille_max;
    		} 
    		else 
    		{
    			$ratio = $this->getLargeur() / $taille_max;
    		}
    		
    		// Définition des dimensions de la miniature
    		$larg_miniature = $this->getLargeur() / $ratio;
    		$haut_miniature = $this->getHauteur() / $ratio;
    		
    		// Crée la ressource image pour la miniature
    		$destination = imagecreatetruecolor($larg_miniature, $haut_miniature);
    		
    		// Retourne un identifiant d'image jpeg, gif ou png
    		$source = $this->call_user_func_1($this->type, $this->chemin_cible.$this->getNom());
    		
    		// Redimensionne la grande image
    		imagecopyresampled( $destination, $source, 
    							0, 0, 0, 0, 
    							$larg_miniature, 
    							$haut_miniature, 
    							$this->getLargeur(), 
    							$this->getHauteur());
    		
    		// Si le répertoire de miniature n'existe pas, on le crée
    		if (!is_dir($this->chemin_cible.$Nom_Dossier_Miniature)) 
    		{
    			mkdir ($this->chemin_cible.$Nom_Dossier_Miniature, 0700);
    		}
    		//Chemin de la nouvelle miniature
    		$chemin_miniature = $this->chemin_cible.$Nom_Dossier_Miniature."/mini_".$this->getNom();
    		print $chemin_miniature;
    		// Ecriture physique de l'image
    		$this->call_user_func_2($this->type, $chemin_miniature);
    		
    		// Détruit les ressources temporaires crées
    		imagedestroy($destination);
    		imagedestroy($source);
    	}
    	//############################################################
    	//# -Fonction pour l'extention du fichier (jpeg,gif ou png)- #
    	//############################################################
    	private function call_user_func_1($extension, $chemin_image)
    	{
    	        // $chemin_image= ./upload_image/P1010012.JPG
                    switch ($extension)
    		{
    		case 'image/jpeg':
    			$source = imagecreatefromjpeg($chemin_image);
    		break;
    		case 'image/gif':
    			$source = imagecreatefromgif($chemin_image);
    		break;
    		case 'image/png':
    			$source = imagecreatefrompng($chemin_image);
    		break;
    		return $source;
    		}
    	}
    	//################################################################
    	//# -Fonction Ecriture physique de l'image avec call_user_func - #
    	//################################################################
    	private function call_user_func_2($extension, $destination, $chemin_miniature)
    	{
                    // $chemin_miniature = ./upload_image/Mini_Image/mini_P1010012.JPG
    		switch ($extension)
    		{
    		case 'image/jpeg':
    			$source = imagejpeg($destination, $chemin_miniature);
    		break;
    		case 'image/gif':
    			$source = imagegif($destination, $chemin_miniature);
    		break;
    		case 'image/png':
    			$source = imagepng($destination, $chemin_miniature);
    		break;
    		return $source;
    		}
    	}
    Les erreurs:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    Warning: imagecopyresampled(): supplied argument is not a valid Image resource in C:\wamp\www\PTI\photo.class.php on line 164
     
    Warning: Missing argument 3 for Photo::call_user_func_2(), called in C:\wamp\www\PTI\photo.class.php on line 175 and defined in C:\wamp\www\PTI\photo.class.php on line 203
     
    Notice: Undefined variable: chemin_miniature in C:\wamp\www\PTI\photo.class.php on line 208
     
    Warning: imagejpeg(): supplied argument is not a valid Image resource in C:\wamp\www\PTI\photo.class.php on line 208
     
    Warning: imagedestroy(): supplied argument is not a valid Image resource in C:\wamp\www\PTI\photo.class.php on line 179
    merci de votre aide ...

  2. #2
    Nouveau membre du Club
    Femme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2009
    Messages
    30
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2009
    Messages : 30
    Points : 36
    Points
    36
    Par défaut
    J'ai trouvé beaucoup d'erreurs dans mon code. Si cela peut aider quelqu'un voici une class photo pour envoyer et miniaturiser les photos. Pour tester la class photo, mettre le code dans photo.class.php ...Mais quand je veux envoyer une photo de format PNG, sa bloque ... si quelqu'un peut me dire comment faire pour palier à cette erreur.

    Code erreur:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    Warning: imagecreatefrompng() [function.imagecreatefrompng]: './upload_image/hebus_207879_1920x1200.png' is not a valid PNG file in C:\wamp\www\PTI\photo.class.php on line 188
     
    Warning: imagecopyresampled(): supplied argument is not a valid Image resource in C:\wamp\www\PTI\photo.class.php on line 163
     
    Warning: imagepng() [function.imagepng]: gd-png: fatal libpng error: zlib failed to initialize compressor -- stream error in C:\wamp\www\PTI\photo.class.php on line 207
     
    Warning: imagepng() [function.imagepng]: gd-png error: setjmp returns error condition in C:\wamp\www\PTI\photo.class.php on line 207
    Class photo:

    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
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    <?php
    class Photo
    {
    			//###############
    			//# -VARIABLES- #
    			//###############	
    	private $nom;
    	private $nom_temporaire;
    	private $type;
    	private $taille_en_octet;
    	private $code_erreur;
    	private $repertoire_cible;
    	private $chemin_cible;	
     
    			//##################
    			//# -CONSTRUCTEUR- #
    			//##################	
        public function __construct($nom, $nom_temporaire, $type, $taille_en_octet, $code_erreur, $repertoire_cible)
    	{
    		$this->nom = $nom;
    		$this->nom_temporaire = $nom_temporaire;
    		$this->type = $type;
    		$this->taille_en_octet = $taille_en_octet;
    		$this->code_erreur = $code_erreur;
    		$this->repertoire_cible = $repertoire_cible;
    		$this->chemin_cible = "./" . $this->repertoire_cible . "/";
    	}
        		//###############
    			//# -ACCESSEUR- #
    			//###############	
    	//Nom
    	public function setNom($nom){
            $this->nom= $nom;
        }
    	public function getNom(){
    		return $this->nom;
    	}
     
    	//getNom_temporaire
    	public function setNom_temporaire($nom_temporaire){
            $this->nom_temporaire= $nom_temporaire;
        }
    	public function getNom_temporaire(){
    		return $this->nom_temporaire;
    	}
     
    	//type
    	public function setType($type){
            $this->type= $type;
        }
    	public function getType(){
    		return $this->type;
    	}
    	//taille_en_octet
    	public function setTaille_en_octet($taille_en_octet){
            $this->taille_en_octet= $taille_en_octet;
        }
    	public function getTaille_en_octet(){
    		return $this->taille_en_octet;
    	}
    	//code_erreur
    	public function setCode_erreur($code_erreur){
            $this->type= $code_erreur;
        }
    	public function getCode_erreur(){
    		return $this->code_erreur;
    	}
    	//repertoire_cible
    	public function setRepertoire_cible($repertoire_cible){
            $this->repertoire_cible= $repertoire_cible;
        }
    	public function getRepertoire_cible(){
    		return $this->repertoire_cible;
    	}
    	//chemin_cible
    	public function setChemin_cible($chemin_cible){
            $this->chemin_cible= $chemin_cible;
        }
    	public function getChemin_cible(){
    		return $this->chemin_cible;
    	}
    	//Retourne la hauteur de l'image
    	//infos_image[0] :largeur de l'image
    	//infos_image[1] :hauteur de l'image
     
    	//Retourne la largeur de l'image
    	public function getLargeur()
    	{
    		$infos_image = getimagesize($this->chemin_cible.$this->nom);
    		$largeurSource = $infos_image[0];
    		return $largeurSource; 
        }
    	//Retourne la hauteur de l'image
    	public function getHauteur()
    	{
            $infos_image = getimagesize($this->chemin_cible.$this->nom);
    		$hauteurSource = $infos_image[1];
    		return $hauteurSource;
        }
     
    			//##############
    			//# -METHODES- #
    			//##############
     
    	//##############################################
    	//# -Procedure pour upload d'un fichier image- #
    	//##############################################	
    	public function upload()  
    	{
       		//on vérifies que le champ est bien rempli:
    		if(!empty($this->nom))
    		{
    			//on vérifie si le fichier est bien copié
    			if(copy($this->nom_temporaire, $this->chemin_cible.$this->nom))
    			{
    				echo("<br>l'upload a réussi") ;
    			}
    			else
    			{
    				echo("<br>l'upload a échoué") ;
    			}
    		}//fin if
    		else
    		{
    			echo("Vous n'avez pas choisi de fichier!!<br>") ;
    			echo("<a href=\"./index.php\">Retour</a>") ;
    		}//fin else
    	}
     
     
    	//###########################################################
    	//# -Génère la miniature de l'image dans le sous-répertoire #
    	//###########################################################
    	// Génère la miniature de l'image dans le sous-répertoire 'miniature' si elle n'existe pas déjà
    	function genere_miniature($Nom_Dossier_Miniature) 
    	{
    		// Calcul du ratio entre la grande image et la miniature
    		$taille_max = 100;
    		if ($this->getLargeur() <= $this->getHauteur()) 
    		{
    			$ratio = $this->getHauteur() / $taille_max;
    		} 
    		else 
    		{
    			$ratio = $this->getLargeur() / $taille_max;
    		}
     
    		// Définition des dimensions de la miniature
    		$larg_miniature = $this->getLargeur() / $ratio;
    		$haut_miniature = $this->getHauteur() / $ratio;
     
    		//Chemin de la nouvelle miniature
    		$chemin_miniature = $this->chemin_cible.$Nom_Dossier_Miniature."/mini_".$this->getNom();
    		$chemin_image = $this->chemin_cible.$this->getNom();
     
    		// Crée la ressource image pour la miniature
    		$destination = imagecreatetruecolor($larg_miniature, $haut_miniature);
     
    		// Retourne un identifiant d'image jpeg, gif ou png
    		$source = $this->call_user_func_1($chemin_image);
     
    		// Redimensionne la grande image
    		imagecopyresampled($destination, $source, 0, 0, 0, 0, $larg_miniature, $haut_miniature,$this->getLargeur(),$this->getHauteur());
     
    		// Si le répertoire de miniature n'existe pas, on le crée
    		if (!is_dir($this->chemin_cible.$Nom_Dossier_Miniature)) 
    		{
    			mkdir ($this->chemin_cible.$Nom_Dossier_Miniature, 0700);
    		}
     
    		// Ecriture physique de l'image
    		$this->call_user_func_2($destination, $chemin_miniature);
    	}
    	//############################################################
    	//# -Fonction pour l'extention du fichier (jpeg,gif ou png)- #
    	//############################################################
    	private function call_user_func_1($chemin_image)
    	{
    		switch ($this->type)
    		{
    		case 'image/jpeg':
    			$source = imagecreatefromjpeg($chemin_image);
    		break;
    		case 'image/gif':
    			$source = imagecreatefromgif($chemin_image);
    		break;
    		case 'image/png':
    			$source = imagecreatefrompng($chemin_image);
    		break;
    		}
    		return $source;
    	}
    	//################################################################
    	//# -Fonction Ecriture physique de l'image avec call_user_func - #
    	//################################################################
    	private function call_user_func_2($destination, $chemin_miniature)
    	{
    		switch ($this->type)
    		{
    		case 'image/jpeg':
    			$source = imagejpeg($destination, $chemin_miniature,75);
    		break;
    		case 'image/gif':
    			$source = imagegif($destination, $chemin_miniature,75);
    		break;
    		case 'image/png':
    			$source = imagepng($destination, $chemin_miniature,75);
    		break;
    		}
    		return $source;
    	}
     
    }
    ?>
    Exemple d'appel des méthodes de la class photo:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    <?php
    	//Redirection avec une include sur la classe photo 
    	include("photo.class.php");
    	//Création d'un objet de la classe photo en appelant le constructeur
    	$p=new Photo($_FILES["fichier_choisi"]["name"], $_FILES["fichier_choisi"]["tmp_name"], $_FILES["fichier_choisi"]["type"], $_FILES["fichier_choisi"]["size"], $_FILES["fichier_choisi"]["error"],"upload_image");
    	//Appel de la procedure upload de la classe photo
    	$p->upload("upload_image");	
    	//TEST
    	$p->genere_miniature("Mini_Image");
    ?>
    merci de de votre aide

  3. #3
    Nouveau membre du Club
    Femme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2009
    Messages
    30
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2009
    Messages : 30
    Points : 36
    Points
    36
    Par défaut
    Après lecture http://www.developpez.net/forums/d72...s/gd-imagepng/ mon problème est résolu.

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

Discussions similaires

  1. Problème de format conditionnel avec condition
    Par Chrisp2 dans le forum Excel
    Réponses: 3
    Dernier message: 29/10/2014, 12h52
  2. Problème de format avec ClustalW
    Par Jasmine80 dans le forum Bioinformatique
    Réponses: 2
    Dernier message: 27/08/2008, 13h30
  3. Problème de transparence GIF et PNG avec Export et SaveAs
    Par nl5nn dans le forum VBA PowerPoint
    Réponses: 2
    Dernier message: 04/03/2008, 21h31
  4. Réponses: 1
    Dernier message: 05/09/2007, 12h47
  5. Problème format Date avec VS2003
    Par vaohdan dans le forum Windows Forms
    Réponses: 1
    Dernier message: 07/05/2007, 12h06

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