/**
  * 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;
 }
Beispiel #2
0
 /**
  * Turns the image by the given amount of degrees.
  * If the hex color is an empty string, then a transparent backgroundcolor is used.
  * The rotation uses a counterclockwise offset.
  * @param integer The amount of degrees to turn
  * @param string The hex color used for the background.
  */
 public final function rotateByDegrees($degrees, $backgroundColor = '')
 {
     $color = imagecolorallocatealpha($this->image, 0, 0, 0, 127);
     if (!empty($backgroundColor)) {
         $r = 0;
         $g = 0;
         $b = 0;
         if (\System\Image\ColorConversion::hexToRGB($backgroundColor, $r, $g, $b)) {
             $color = imagecolorallocate($this->image, $r, $g, $b);
         }
     }
     $this->image = imagerotate($this->image, $degrees, $color);
     imagesavealpha($this->image, true);
 }
Beispiel #3
0
 /**
  * Turns the image by the given amount of degrees.
  * If the hex color is an empty string, then a transparent backgroundcolor is used.
  * The rotation uses a counterclockwise offset.
  * @param integer The amount of degrees to turn
  * @param string The hex color used for the background.
  */
 public final function rotateByDegrees($degrees, $backgroundColor = '')
 {
     $r = 0;
     $g = 0;
     $b = 0;
     if (!empty($backgroundColor)) {
         \System\Image\ColorConversion::hexToRGB($backgroundColor, $r, $g, $b);
     }
     $this->image->rotateImage(new \ImagickPixel('rgb(' . $r . ',' . $g . ',' . $b . ')'), -$degrees);
 }