Image_GD::_do_reflection PHP Method

_do_reflection() protected method

Execute a reflection.
protected _do_reflection ( integer $height, integer $opacity, boolean $fade_in ) : void
$height integer reflection height
$opacity integer reflection opacity
$fade_in boolean TRUE to fade out, FALSE to fade in
return void
    protected function _do_reflection($height, $opacity, $fade_in)
    {
        if (!function_exists('imagefilter')) {
            throw new CException('This method requires imagefilter, which is only available in the bundled version of GD');
        }
        // Loads image if not yet loaded
        $this->_load_image();
        // Convert an opacity range of 0-100 to 127-0
        $opacity = round(abs($opacity * 127 / 100 - 127));
        if ($opacity < 127) {
            // Calculate the opacity stepping
            $stepping = (127 - $opacity) / $height;
        } else {
            // Avoid a "divide by zero" error
            $stepping = 127 / $height;
        }
        // Create the reflection image
        $reflection = $this->_create($this->width, $this->height + $height);
        // Copy the image to the reflection
        imagecopy($reflection, $this->_image, 0, 0, 0, 0, $this->width, $this->height);
        for ($offset = 0; $height >= $offset; $offset++) {
            // Read the next line down
            $src_y = $this->height - $offset - 1;
            // Place the line at the bottom of the reflection
            $dst_y = $this->height + $offset;
            if ($fade_in === TRUE) {
                // Start with the most transparent line first
                $dst_opacity = round($opacity + $stepping * ($height - $offset));
            } else {
                // Start with the most opaque line first
                $dst_opacity = round($opacity + $stepping * $offset);
            }
            // Create a single line of the image
            $line = $this->_create($this->width, 1);
            // Copy a single line from the current image into the line
            imagecopy($line, $this->_image, 0, 0, 0, $src_y, $this->width, 1);
            // Colorize the line to add the correct alpha level
            imagefilter($line, IMG_FILTER_COLORIZE, 0, 0, 0, $dst_opacity);
            // Copy a the line into the reflection
            imagecopy($reflection, $line, 0, $dst_y, 0, 0, $this->width, 1);
        }
        // Swap the new image for the old one
        imagedestroy($this->_image);
        $this->_image = $reflection;
        // Reset the width and height
        $this->width = imagesx($reflection);
        $this->height = imagesy($reflection);
    }