Codeigniter and image transparency

CodeigniterPublished June 16, 2011 at 9:37 PM No Comments

If you want to maintain transparency of your PNG images when you use Codeigniter image library, you need to make some tweak on Codeigniter image library:
1. file path: system/libraries/image_lib.php
2. find: $dst_img = $create($this->width, $this->height);
3. insert after:
$transparencyIndex = imagecolortransparent($src_img);
$transparencyColor = array('red' => 255, 'green' => 255, 'blue' => 255);

if ($transparencyIndex >= 0) {
$transparencyColor = imagecolorsforindex($src_img, $transparencyIndex);
}

$transparencyIndex = imagecolorallocate($dst_img, $transparencyColor['red'], $transparencyColor['green'], $transparencyColor['blue']);
imagefill($dst_img, 0, 0, $transparencyIndex);
imagecolortransparent($dst_img, $transparencyIndex);

4. This is not anymore necessari if you upgrade at 2.0.2

Leave a Reply

(required)

(required)