Zebra_Image::_prepare_image PHP Method

_prepare_image() private method

@param integer $width Width of the new image.
private _prepare_image ( integer $width, integer $height, string $background_color = '#FFFFFF' ) : Returns
$width integer
$height integer 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
$background_color string
return Returns
    private 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;
    }