Пример #1
0
 /**
  * Applies the image effect on a GD resource. This function should be overridden by the effect.
  * @param resource The image resource to work with
  * @return resource The resource to use
  */
 protected final function executeFilterGD($imageData)
 {
     $width = imagesx($imageData);
     $height = imagesy($imageData);
     //we make sure we cannot go out of bounds
     if ($this->reflectionHeight > $height) {
         $this->reflectionHeight = $height;
     }
     //create a new image with alpha channels
     $image = imagecreatetruecolor($width, $height + $this->reflectionHeight + $this->gradientDistance - 1);
     imagesavealpha($image, true);
     //use the proper color for the background and fill
     if (!empty($this->reflectionBackgroundColor)) {
         $val = new \System\Security\Validate();
         if ($val->isHexColor($this->reflectionBackgroundColor, 'color', true) == \System\Security\ValidateResult::VALIDATE_OK) {
             $r = 0;
             $g = 0;
             $b = 0;
             \System\Image\ColorConversion::hexToRGB($this->reflectionBackgroundColor, $r, $g, $b);
             $transparentColor = imagecolorallocatealpha($image, $r, $g, $b, 0);
         }
     } else {
         $transparentColor = imagecolorallocatealpha($image, 0, 0, 0, 127);
     }
     imagefill($image, 0, 0, $transparentColor);
     //copy the original image into the newimage
     imagecopy($image, $imageData, 0, 0, 0, 0, $width, $height);
     $transparencyStep = 127 / $this->reflectionHeight;
     //copy the bottom $reflectionHeight pixels of the image and make them transparent
     for ($y = $height - 1; $y >= $height - $this->reflectionHeight; $y--) {
         for ($x = 0; $x < $width; $x++) {
             $colors = imagecolorsforindex($imageData, imagecolorat($imageData, $x, $y));
             $alpha = intval(round($transparencyStep * ($height - $y)));
             if ($colors['alpha'] > $alpha) {
                 $alpha = $colors['alpha'];
             }
             $newColor = imagecolorallocatealpha($image, $colors['red'], $colors['green'], $colors['blue'], $alpha);
             imagesetpixel($image, $x, $height + ($height - $y) + $this->gradientDistance - 1, $newColor);
         }
     }
     imagedestroy($imageData);
     return $image;
 }
Пример #2
0
 /**
  * Converts a HEX color (3 or 6 digits, in- or excluding #) to RGB colors.
  * @param string 3 or 6 digit hex code, optionally preceded by #
  * @param integer The red component by reference
  * @param integer The green component by reference
  * @param integer The blue component by reference
  * @return boolean True on succes, false otherwise
  */
 public static final function hexToRGB($hex, &$r = 0, &$g = 0, &$b = 0)
 {
     $val = new \System\Security\Validate();
     if ($val->isHexColor($hex, 'color', true) != \System\Security\ValidateResult::VALIDATE_OK) {
         return false;
     }
     $hex = str_replace('#', '', $hex);
     if (strlen($hex) == 3) {
         $r = hexdec(substr($hex, 0, 1));
         $g = hexdec(substr($hex, 1, 1));
         $b = hexdec(substr($hex, 2, 1));
         $r *= $r;
         $g *= $g;
         $b *= $b;
     } else {
         $r = hexdec(substr($hex, 0, 2));
         $g = hexdec(substr($hex, 2, 2));
         $b = hexdec(substr($hex, 4, 2));
     }
     return true;
 }