Modifier teinte d'un png transparent

kek
Eléphanteau du PHP | 16 Messages

08 mars 2009, 16:16

Hello,

je cherche à modifier la teinte d'un png transparent, avec la librairie GD.
Je peux modifier la teinte d'un png classique, mais dès qu'il est transparent, il me ressort un png sans transparence..

voilà mon code, par exemple pour modifier le gamma :

Code : Tout sélectionner

// ouvre l'image d'origine $theimage = "test.png"; $im = imagecreatefrompng($theimage); // détermine sa taille $size = getimagesize($theimage); $w = $size[0]; $h = $size[1]; // crée l'image de sortie $im2 = imagecreatetruecolor($w/2,$h/2); imagealphablending($im2,false); imagesavealpha($im2,true); // remplit l'image de sortie imagecopyresampled($im2,$im,0,0,0,0,$w/2,$h/2,$w,$h); //Modifie le gamma au passage imagegammacorrect($im2,1,2.2); // affiche l'image header("Content-type: image/x-png" ); imagepng($im2);
merci à qui pourra m'aider !
Sinon il faudra que je regarde vers imagemagick apparemment..
kek
www.zanorg.com
trucs à la con

kek
Eléphanteau du PHP | 16 Messages

09 mars 2009, 15:52

bon ben apparemment c'est pas possible ? Pourtant ce serait super pratique :(
www.zanorg.com
trucs à la con

Eléphant du PHP | 185 Messages

09 mars 2009, 19:05

<?php
 // ouvre l'image d'origine 
 $theimage = "test.png"; 
 $im = imagecreatefrompng($theimage); 

 // détermine sa taille 
 $size = getimagesize($theimage); 
 $w = $size[0]; 
 $h = $size[1]; 

 // crée l'image de sortie 
 $im2 =  imagecreatetruecolor($w/2,$h/2);

$transparent = imagecolortransparent( $im );
if($transparent >= 0 && $transparent < imagecolorstotal( $im )) {
    $transparentcolor = imagecolorsforindex( $im, $transparent );
    $newtransparentcolor = imagecolorallocate(
        $im2,
        $transparentcolor['red'],
        $transparentcolor['green'],
        $transparentcolor['blue']
    );
    imagefill( $imtn, 0, 0, $newtransparentcolor );
    imagecolortransparent( $im2, $newtransparentcolor );
}

 imagealphablending($im2,false); 
 imagesavealpha($im2,true); 

 // remplit l'image de sortie 
 imagecopyresampled($im2,$im,0,0,0,0,$w/2,$h/2,$w,$h); 

//Modifie le gamma au passage 
 imagegammacorrect($im2,1,2.2); 

 // affiche l'image 
 header("Content-type: image/x-png" ); 
 imagepng($im2);
J'ai ça à te proposer (http://fr.php.net/manual/fr/function.im ... .php#76648). Si ça marche pas bah... J'ai rien d'autre ^^