how is it possible to save my image, created with gd, as an png-8?
it saves as gif with transparent channel well - but I want to use png-8.
Best Regards, Beerweasle
how is it possible to save my image, created with gd, as an png-8?
it saves as gif with transparent channel well - but I want to use png-8.
Best Regards, Beerweasle
Using imagesavealpha()
and a transparent bg color should do the trick...
Based on dfilkovi s code:
<?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);
?>
@Sonny
false assumption: PNG of any bit depth can have transparency. It is recorded in the tRNS chunk of the png image (except for truecolor ones) cf format definition
cf www.libpng.org/pub/png/spec/1.2/PNG-Chunks.html#C.tRNS
idem www.w3.org/TR/PNG-Chunks.html#C.tRNS
The difference is how it is recorder: RGBA has a unique record per pixel, with 4 values (3 colors and 1 alpha channel), where "paletted" PNG records alpha channel in its own chunk.
Fireworks is very good at it.
Examples:
I think this could help you.
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);
?>
this should make 8bit png
Building on dfilkovi s solution, have you tried using imagesavealpha() to save the full alpha channel information?
I had to add the line imagecolortransparent($im, $alphabg); to the following code (taken from previous answer) for this to work:
// 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);
?>
I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...
<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...
I found this script online that creates a thumbnail out of a image but the thumbnail image is created with poor quality how can I improve the quality of the image. And is there a better way to create ...
如何确认来自正确来源的数字。
Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...
I wonder there is a way to post a message to a facebook business page with cURL? thanks
I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...
How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...