This post is my experience, when i've got the problem about resizing image with transparent background, that
transparent part of the result image wasn't transparent any more, but it changed by black.
the first solution that i found was in the CI's forum ( http://codeigniter.com/forums/viewthread/62955/ ).
But it didn't work in png file. I was thinking, it might be the numerical representation of transparent
color was different beetwen png and gif.
And then i found another solution in the PHP's web
(http://www.php.net/manual/en/function.imagecolortransparent.php), that observed png and gif.
My implementation about that problem :
change the CI's image library (system/libraries/Image_lib.php), at funcion image_process_gd() after
"$dst_img = $create($this->width, $this->height);" code(about line 515 in CI V1.7).
the inserted code :
$transparent_index = imagecolortransparent($src_img);
//for gif
if ($transparent_index >= 0) {
imagepalettecopy($src_img, $dst_img);
imagefill($dst_img, 0, 0, $transparent_index);
imagecolortransparent($dst_img, $transparent_index);
imagetruecolortopalette($dst_img, true, 256);
}
// for png
else{
imagealphablending($dst_img, false);
$colorTransparent = imagecolorallocatealpha($dst_img, 0, 0, 0, 127);
imagefill($dst_img, 0, 0, $colorTransparent);
imagesavealpha($dst_img, true);
}
Finally the case is closed.hahaha.....
--------------------- sharing always increases your experience point ------------------------------
Tuesday, January 5, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment