CodeIgniter的Image_lib可以快速的產生所想要的縮圖,也可以方便的加入浮水印,不過官方原始的類別無法處理PNG的透明背景層,所有含有透明背景的圖片都會變成黑色的背景。

最近剛好使用到也遇到了問題/__\,幸好透過官方的討論區,找到其它玩家的解決方式。你可以從這篇討論文章的串文,看到原文的解決方式,不過我仍然將解決的方式,重新發表在這邊分享給遇到同樣問題的人。

作法是直接去修改有問題的CI核心image_lib檔,位置在system/ libraries / Image_lib.php,搜尋第514行,接著將此行註解後,補上修改的程式碼插入到518行之前,最後結果如下:

//$dst_img = $create($this->width, $this->height); ← 這行(514行)之後
$dst_img = imagecreatetruecolor($this->width, $this->height);
$transparent = imagecolorallocatealpha($dst_img,0,255,0,127);
imagefill($dst_img,0,0,$transparent);

$copy($dst_img, $src_img, 0, 0, $this->x_axis, $this->y_axis, $this->width, $this->height, $this->orig_width, $this->orig_height);

imageAlphaBlending($dst_img, false);
imageSaveAlpha($dst_img, true);

//  Show the image ←這行(518行)之前

我使用CI1.7.1版本,透過修改後,問題獲得解決了,然而這個問題我也已經回報給官方了,不過到哪個版本才會修正就不知道了

arrow
arrow
    全站熱搜

    低溫烘培 發表在 痞客邦 留言(0) 人氣()