Generer une image avec transparence

Répondre
maxroucool
maxroucool
Déconnecté
Slt tlm,

je veux créer une miniature d'une image png qui contient des pixels transparents. Seulement, avec le bout de code qui suit, les pixels transparents sont replacés en pixels noirs.

  1. <?php
  2. $src = imagecreatefrompng($srcImg); 
  3.             
  4. $dstImg = imagecreatetruecolor($newWidth, $newHeight);  
  5.  
  6. imagecopyresampled($dstImg, $src, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);  
  7.  
  8. imagepng($dstImg, $dirDest.$nameImgApercu);  
  9. ?> 


Merci bp!
LA GLOBULE
LA GLOBULE
Déconnecté
111 111 111 x 111 111 111 = 12 345 678 987 654 321
Il faut sauver le canal alpha de ton PNG avant de redimensionner le truc :

  1. <?php
  2. $srcImg = 'pom.png';  
  3. $newWidth = 80;  
  4. $newHeight = 80;  
  5.  
  6. $width = 256;  
  7. $height = 256;  
  8.  
  9. $src = imagecreatefrompng($srcImg);  
  10. $dstImg = imagecreatetruecolor($newWidth, $newHeight);  
  11.  
  12. imagealphablending($dstImg, false);  
  13. imagesavealpha($dstImg, true);  
  14.  
  15. imagecopyresized($dstImg, $src, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);  
  16.  
  17. imagepng($dstImg, 'mini.png');  
  18. ?> 


Enjoy :)
maxroucool
maxroucool
Déconnecté
ok merci, ca marche nickel.

Mais j'ai oublier de demander comment faire la meme chose avec un gif.

D'autre part, y a-t-il un moment précis pour utiliser la fonction imagerotate() car elle ne fonctionne pas.
Pour info, je l'utilise entre imagecopyresampled() et le header


+++
LA GLOBULE
LA GLOBULE
Déconnecté
111 111 111 x 111 111 111 = 12 345 678 987 654 321
Pour un gif, j'ai fais çà :

  1. <?php
  2. $src = imagecreatefromgif($srcImg);  
  3. $dstImg = imagecreatetruecolor($newWidth, $newHeight);  
  4.  
  5. $white = imagecolorallocate($dstImg, 255, 255, 255);  
  6.  
  7. imagefill($dstImg, 0, 0, $white);  
  8. imageColorTransparent($dstImg, $white);  
  9. imagecopyresampled($dstImg, $src, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);  
  10.  
  11. imagegif($dstImg, 'mini.gif');  
  12. ?> 


Mais le résultat n'est pas top.

Je chercherais sur le net demain.

Pour le imagerotate, j'ai repris l'exemple du manuel PHP, et il fonctionne sans problème.
Répondre
Accès rapide :

Remonter Remonter
L'éditeur javascript - CSS - Gentoo - Tutoriaux PHP - Tutoriels PHP - Php