note 60128 added to function.imagepng
| From: | adrenalin at NOSPAM dot myrealbox dot com | Date: | Tue, 27 Dec 2005 15:22:32 +0000 |
| Subject: | note 60128 added to function.imagepng | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-100798@lists.php.net to get a copy of this message | ||
Trying to resize a png 256 colors image and save it in 256 colors with a correct color palette ? (if
you'll save a 256 color image in truecolor palette the result image will have a big size).
I spent some hours trying various function to get a good quality 256 color png image, but because of
color palette the result image quality was awful.
But thank to the comment of zmorris at zsculpt dot com from imagetruecolortopalette function page, i
figured out how to get a properly image!
<?php
function resize_png($src,$dst,$dstw,$dsth) {
list($width, $height, $type, $attr) = getimagesize($src);
$im = imagecreatefrompng($src);
$tim = imagecreatetruecolor($dstw,$dsth);
imagecopyresampled($tim,$im,0,0,0,0,$dstw,$dsth,$width,$height);
$tim = ImageTrueColorToPalette2($tim,false,255);
imagepng($tim,$dst);
}
//zmorris at zsculpt dot com function, a bit completed
function ImageTrueColorToPalette2($image, $dither, $ncolors) {
$width = imagesx( $image );
$height = imagesy( $image );
$colors_handle = ImageCreateTrueColor( $width, $height );
ImageCopyMerge( $colors_handle, $image, 0, 0, 0, 0, $width, $height, 100 );
ImageTrueColorToPalette( $image, $dither, $ncolors );
ImageColorMatch( $colors_handle, $image );
ImageDestroy($colors_handle);
return $image;
}
?>
Good luck,
Namolovan Nicolae, Moldova
----
Manual Page -- http://www.php.net/manual/en/function.imagepng.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+60128
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60128&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60128&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60128&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60128&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60128&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60128&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60128&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+60128&report=yes
Search -- http://master.php.net/manage/user-notes.php