CI中的CI_Image_lib类不能生成背景透明的png或gif缩略图,以下是我的解决办法,重新创建一个MY_Image_lib类,并继承CI_Image_lib类,然后重写一下image_process_gd方法。
先在CI_Image_lib中找到image_process_gd方法,然后把这个方法的全部代码复制到MY_Image_lib类中,然后查找下面这行代码:
$dst_img = $create($this->width, $this->height);
接着在找到的这行代码下面添加如下代码:
$transparent = imagecolortransparent($src_img, imagecolorallocate($src_img, 0, 0, 0));
if ($transparent >= 0) {
imagecolortransparent($dst_img, $transparent);
imagealphablending($dst_img, false);
imagesavealpha($dst_img, true);
}

Posted in
Tags: