CImage.php
private function createImageKeepTransparency($width, $height)
    {
        $this->log("Creating a new working image width={$width}px, height={$height}px.");
        $img = imagecreatetruecolor($width, $height);
        imagealphablending($img, false);
        imagesavealpha($img, true);

        $index = $this->image
            ? imagecolortransparent($this->image)
            : -1;

        if ($index != -1) {

            imagealphablending($img, true);
            $transparent = imagecolorsforindex($this->image, $index);
            $color = imagecolorallocatealpha($img, $transparent['red'], $transparent['green'], $transparent['blue'], $transparent['alpha']);
            imagefill($img, 0, 0, $color);
            $index = imagecolortransparent($img, $color);
            $this->Log("Detected transparent color = " . implode(", ", $transparent) . " at index = $index");

        } elseif ($this->bgColorDefault) {

            $color = $this->getBackgroundColor($img);
            imagefill($img, 0, 0, $color);
            $this->Log("Filling image with background color.");
        }

        return $img;
    }
private function createImageKeepTransparency($width, $height)
    {
        $this->log("Creating a new working image width={$width}px, height={$height}px.");
        $img = imagecreatetruecolor($width, $height);
        imagealphablending($img, false);
        imagesavealpha($img, true);

        $index = $this->image
            ? imagecolortransparent($this->image)
            : -1;

        if ($index != -1) {

            imagealphablending($img, true);
            $transparent = imagecolorsforindex($this->image, $index);
            $color = imagecolorallocatealpha($img, $transparent['red'], $transparent['green'], $transparent['blue'], $transparent['alpha']);
            imagefill($img, 0, 0, $color);
            $index = imagecolortransparent($img, $color);
            $this->Log("Detected transparent color = " . implode(", ", $transparent) . " at index = $index");

        } elseif ($this->bgColorDefault) {

            $color = $this->getBackgroundColor($img);
            imagefill($img, 0, 0, $color);
            $this->Log("Filling image with background color.");
        }

        return $img;
    }
private function createImageKeepTransparency ( $ width , $ height ) { $ this -> log ( "Creating a new working image width={$width}px, height={$height}px." ) ; $ img = imagecreatetruecolor ( $ width , $ height ) ; imagealphablending ( $ img , false ) ; imagesavealpha ( $ img , true ) ; $ index = $ this -> image ? imagecolortransparent ( $ this -> image ) : - 1 ; if ( $ index != - 1 ) { imagealphablending ( $ img , true ) ; $ transparent = imagecolorsforindex ( $ this -> image , $ index ) ; $ color = imagecolorallocatealpha ( $ img , $ transparent [ 'red' ] , $ transparent [ 'green' ] , $ transparent [ 'blue' ] , $ transparent [ 'alpha' ] ) ; imagefill ( $ img , 0 , 0 , $ color ) ; $ index = imagecolortransparent ( $ img , $ color ) ; $ this -> Log ( "Detected transparent color = " . implode ( ", " , $ transparent ) . " at index = $index" ) ; } elseif ( $ this -> bgColorDefault ) { $ color = $ this -> getBackgroundColor ( $ img ) ; imagefill ( $ img , 0 , 0 , $ color ) ; $ this -> Log ( "Filling image with background color." ) ; } return $ img ; }
Create a image and keep transparency for png and gifs.

@param int $width of the new image.
@param int $height of the new image.

@return image resource.
Create a image and keep transparency for png and gifs .