function _prepare_image($width, $height, $background_color = '#FFFFFF')
    {

        // create a blank image
        $identifier = imagecreatetruecolor((int)$width <= 0 ? 1 : (int)$width, (int)$height <= 0 ? 1 : (int)$height);

        // if we are creating a PNG image
        if ($this->target_type == 'png' && $background_color == -1) {

            // disable blending
            imagealphablending($identifier, false);

            // allocate a transparent color
            $transparent_color = imagecolorallocatealpha($identifier, 0, 0, 0, 127);

            // fill the image with the transparent color
            imagefill($identifier, 0, 0, $transparent_color);

            //save full alpha channel information
            imagesavealpha($identifier, true);

            // if source image is a transparent GIF
        } elseif ($this->target_type == 'gif' && $background_color == -1 && $this->source_transparent_color_index >= 0) {

            // allocate the source image's transparent color also to the new image resource
            $transparent_color = imagecolorallocate(
                $identifier,
                $this->source_transparent_color['red'],
                $this->source_transparent_color['green'],
                $this->source_transparent_color['blue']
            );

            // fill the background of the new image with transparent color
            imagefill($identifier, 0, 0, $transparent_color);

            // from now on, every pixel having the same RGB as the transparent color will be transparent
            imagecolortransparent($identifier, $transparent_color);

            // for other image types
        } else {

            // if transparent background color specified, revert to white
            if ($background_color == -1) {
                $background_color = '#FFFFFF';
            }

            // convert hex color to rgb
            $background_color = $this->_hex2rgb($background_color);

            // prepare the background color
            $background_color = imagecolorallocate(
                $identifier,
                $background_color['r'],
                $background_color['g'],
                $background_color['b']
            );

            // fill the image with the background color
            imagefill($identifier, 0, 0, $background_color);

        }

        // return the image's identifier
        return $identifier;

    }
function _prepare_image($width, $height, $background_color = '#FFFFFF')
    {

        // create a blank image
        $identifier = imagecreatetruecolor((int)$width <= 0 ? 1 : (int)$width, (int)$height <= 0 ? 1 : (int)$height);

        // if we are creating a PNG image
        if ($this->target_type == 'png' && $background_color == -1) {

            // disable blending
            imagealphablending($identifier, false);

            // allocate a transparent color
            $transparent_color = imagecolorallocatealpha($identifier, 0, 0, 0, 127);

            // fill the image with the transparent color
            imagefill($identifier, 0, 0, $transparent_color);

            //save full alpha channel information
            imagesavealpha($identifier, true);

            // if source image is a transparent GIF
        } elseif ($this->target_type == 'gif' && $background_color == -1 && $this->source_transparent_color_index >= 0) {

            // allocate the source image's transparent color also to the new image resource
            $transparent_color = imagecolorallocate(
                $identifier,
                $this->source_transparent_color['red'],
                $this->source_transparent_color['green'],
                $this->source_transparent_color['blue']
            );

            // fill the background of the new image with transparent color
            imagefill($identifier, 0, 0, $transparent_color);

            // from now on, every pixel having the same RGB as the transparent color will be transparent
            imagecolortransparent($identifier, $transparent_color);

            // for other image types
        } else {

            // if transparent background color specified, revert to white
            if ($background_color == -1) {
                $background_color = '#FFFFFF';
            }

            // convert hex color to rgb
            $background_color = $this->_hex2rgb($background_color);

            // prepare the background color
            $background_color = imagecolorallocate(
                $identifier,
                $background_color['r'],
                $background_color['g'],
                $background_color['b']
            );

            // fill the image with the background color
            imagefill($identifier, 0, 0, $background_color);

        }

        // return the image's identifier
        return $identifier;

    }
function _prepare_image ( $ width , $ height , $ background_color = '#FFFFFF' ) { // create a blank image $ identifier = imagecreatetruecolor ( ( int ) $ width <= 0 ? 1 : ( int ) $ width , ( int ) $ height <= 0 ? 1 : ( int ) $ height ) ; // if we are creating a PNG image if ( $ this -> target_type == 'png' && $ background_color == - 1 ) { // disable blending imagealphablending ( $ identifier , false ) ; // allocate a transparent color $ transparent_color = imagecolorallocatealpha ( $ identifier , 0 , 0 , 0 , 127 ) ; // fill the image with the transparent color imagefill ( $ identifier , 0 , 0 , $ transparent_color ) ; //save full alpha channel information imagesavealpha ( $ identifier , true ) ; // if source image is a transparent GIF } elseif ( $ this -> target_type == 'gif' && $ background_color == - 1 && $ this -> source_transparent_color_index >= 0 ) { // allocate the source image's transparent color also to the new image resource $ transparent_color = imagecolorallocate ( $ identifier , $ this -> source_transparent_color [ 'red' ] , $ this -> source_transparent_color [ 'green' ] , $ this -> source_transparent_color [ 'blue' ] ) ; // fill the background of the new image with transparent color imagefill ( $ identifier , 0 , 0 , $ transparent_color ) ; // from now on, every pixel having the same RGB as the transparent color will be transparent imagecolortransparent ( $ identifier , $ transparent_color ) ; // for other image types } else { // if transparent background color specified, revert to white if ( $ background_color == - 1 ) { $ background_color = '#FFFFFF' ; } // convert hex color to rgb $ background_color = $ this -> _hex2rgb ( $ background_color ) ; // prepare the background color $ background_color = imagecolorallocate ( $ identifier , $ background_color [ 'r' ] , $ background_color [ 'g' ] , $ background_color [ 'b' ] ) ; // fill the image with the background color imagefill ( $ identifier , 0 , 0 , $ background_color ) ; } // return the image's identifier return $ identifier ; }
Creates a blank image of given width, height and background color.

@param  integer $width Width of the new image.

@param  integer $height Height of the new image.

@param  string $background_color (Optional) The hexadecimal color of the background.

Can also be -1 case in which the script will try to create a transparent
image, if possible.

Default is "#FFFFFF".

@return                                 Returns the identifier of the newly created image.

@access private
Creates a blank image of given width height and background color .