PHP GDLib 8 bits PNG avec alpha
Question
comment est-il possible d'enregistrer mon image, créé avec Gd, comme .png-8?
enregistre gif avec canal transparent bien - mais je veux utiliser .png-8
.Cordialement, Beerweasle
La solution
Utilisation imagesavealpha () et une couleur bg transparent devrait faire l'affaire ...
D'après le code de dfilkovi:
<?php
// Create a new true color image
$im = new imagecreatetruecolor(100, 100);
// Fill with alpha background
$alphabg = imagecolorallocatealpha($im, 0, 0, 0, 127);
imagefill($im, 0, 0, $alphabg);
// Convert to palette-based with no dithering and 255 colors with alpha
imagetruecolortopalette($im, false, 255);
imagesavealpha($im, true);
// Save the image
imagepng($im, './paletteimage.png');
imagedestroy($im);
?>
Autres conseils
@Sonny
fausse hypothèse: PNG d'une profondeur de bits peut avoir la transparence. Il est enregistré dans le morceau tRNS de l'image .png (sauf pour les truecolor) définition de format cf
cf www.libpng.org/pub/png/spec/1.2/PNG-Chunks.html#C.tRNS
idem www.w3.org/TR/PNG-Chunks.html#C.tRNS
La différence est la façon dont il est l'enregistreur. RGBA a un enregistrement unique par pixel, avec 4 valeurs (3 couleurs et 1 canal alpha), où « palettisées » enregistrements PNG canal alpha dans son propre morceau
Feux d'artifice est très bon.
Exemples:
Je devais ajouter la imagecolortransparent ligne ($ im, $ alphabg); au code suivant (extrait de la réponse précédente) pour que cela fonctionne:
// Fill with alpha background
$alphabg = imagecolorallocatealpha($im, 0, 0, 0, 127);
imagecolortransparent($im, $alphabg);
imagefill($im, 0, 0, $alphabg);
// Convert to palette-based with no dithering and 255 colors with alpha
imagetruecolortopalette($im, false, 255);
imagesavealpha($im, true);
// Save the image
imagepng($im, './paletteimage.png');
imagedestroy($im);
?>
Je pense que cela pourrait vous aider.
http://roseindia.net/tutorial/php/phpgd/About -transparent.html
<?php
// Create a new true color image
$im = new imagecreatetruecolor(100, 100);
// Convert to palette-based with no dithering and 255 colors
imagetruecolortopalette($im, false, 255);
// Save the image
imagepng($im, './paletteimage.png');
imagedestroy($im);
?>
devrait 8bit .png
Miser sur la solution de dfilkovi, avez-vous essayé d'utiliser imagesavealpha () pour enregistrer les informations complètes du canal alpha ?