Esempio n. 1
0
 /**
  * Returns rotated image
  *
  * @param WideImage_Image $image
  * @param numeric $angle
  * @param int $bgColor
  * @param bool $ignoreTransparent
  * @return WideImage_Image
  */
 function execute($image, $angle, $bgColor, $ignoreTransparent)
 {
     $angle = -floatval($angle);
     if ($angle < 0) {
         $angle = 360 + $angle;
     }
     $angle = $angle % 360;
     if ($angle == 0) {
         return $image->copy();
     }
     if ($bgColor === null) {
         if ($image->isTransparent()) {
             $bgColor = $image->getTransparentColor();
         } else {
             $tc = array('red' => 255, 'green' => 255, 'blue' => 255, 'alpha' => 127);
             if ($image->isTrueColor()) {
                 $bgColor = $image->getExactColorAlpha($tc);
                 if ($bgColor == -1) {
                     $bgColor = $image->allocateColorAlpha($tc);
                 }
             } else {
                 $bgColor = $image->getExactColor($tc);
                 if ($bgColor == -1) {
                     $bgColor = $image->allocateColor($tc);
                 }
             }
         }
     }
     return new WideImage_TrueColorImage(imagerotate($image->getHandle(), $angle, $bgColor, $ignoreTransparent));
 }
Esempio n. 2
0
 /**
  * Apply the manipulation with the setup options to the passed in image.
  * This does not do any memory manipulation
  *
  * @param WideImage_Image $image
  * @return WideImage_Image
  */
 public function &apply(WideImage_Image &$image)
 {
     if (!$this->isSetup()) {
         throw new RokGallery_Manipulation_Exception(rc__('ROKGALLERY_MANIPULATION_WAS_NOT_SETUP_PRIOR_TO_APPLYING'));
     }
     $return_image = $image->resize($this->width, $this->height);
     return $return_image;
 }
 /**
  * Executes imagegammacorrect()
  *
  * @param WideImage_Image $image
  * @param numeric $input_gamma
  * @param numeric $output_gamma
  * @return WideImage_TrueColorImage
  */
 function execute($image, $input_gamma, $output_gamma)
 {
     $new = $image->copy();
     if (!imagegammacorrect($new->getHandle(), $input_gamma, $output_gamma)) {
         throw new WideImage_GDFunctionResultException("imagegammacorrect() returned false");
     }
     return $new;
 }
Esempio n. 4
0
 /**
  * Executes imageconvolution() filter.
  *
  * @param WideImage_Image $image
  * @param array           $matrix
  * @param numeric         $div
  * @param numeric         $offset
  *
  * @return WideImage_Image
  */
 public function execute($image, $matrix, $div, $offset)
 {
     $new = $image->asTrueColor();
     if (!imageconvolution($new->getHandle(), $matrix, $div, $offset)) {
         throw new WideImage_GDFunctionResultException('imageconvolution() returned false');
     }
     return $new;
 }
Esempio n. 5
0
 /**
  * Returns a mirrored image
  *
  * @param WideImage_Image $image
  * @return WideImage_Image
  */
 function execute($image)
 {
     $new = $image->copy();
     $width = $image->getWidth();
     $height = $image->getHeight();
     for ($x = 0; $x < $width; $x++) {
         imagecopy($new->getHandle(), $image->getHandle(), $x, 0, $width - $x - 1, 0, 1, $height);
     }
     return $new;
 }
Esempio n. 6
0
 /**
  * Returns a flipped image
  *
  * @param WideImage_Image $image
  * @return WideImage_Image
  */
 function execute($image)
 {
     $new = $image->copy();
     $width = $image->getWidth();
     $height = $image->getHeight();
     for ($y = 0; $y < $height; $y++) {
         imagecopy($new->getHandle(), $image->getHandle(), 0, $y, 0, $height - $y - 1, $width, 1);
     }
     return $new;
 }
Esempio n. 7
0
 /**
  * Rotates and mirrors and image properly based on current orientation value
  *
  * @param WideImage_Image $img
  * @param int $orientation
  * @return WideImage_Image
  */
 function execute($img, $orientation)
 {
     switch ($orientation) {
         case 2:
             return $img->mirror();
             break;
         case 3:
             return $img->rotate(180);
             break;
         case 4:
             return $img->rotate(180)->mirror();
             break;
         case 5:
             return $img->rotate(90)->mirror();
             break;
         case 6:
             return $img->rotate(90);
             break;
         case 7:
             return $img->rotate(-90)->mirror();
             break;
         case 8:
             return $img->rotate(-90);
             break;
         default:
             return $img->copy();
     }
 }
Esempio n. 8
0
 /**
  * Returns a greyscale copy of an image
  *
  * @param WideImage_Image $image
  * @return WideImage_Image
  */
 function execute($image)
 {
     $new = $image->asTrueColor();
     if (!imagefilter($new->getHandle(), IMG_FILTER_GRAYSCALE)) {
         throw new WideImage_GDFunctionResultException("imagefilter() returned false");
     }
     if (!$image->isTrueColor()) {
         $new = $new->asPalette();
     }
     return $new;
 }
Esempio n. 9
0
 /**
  * Apply the manipulation with the setup options to the passed in image.
  * This does not do any memory manipulation
  *
  * @param WideImage_Image $image
  * @return WideImage_Image
  */
 public function &apply(WideImage_Image &$image)
 {
     if (!$this->isSetup()) {
         throw new RokGallery_Manipulation_Exception(rc__('ROKGALLERY_MANIPULATION_WAS_NOT_SETUP_PRIOR_TO_APPLYING'));
     }
     if ($this->left == 0 && $this->top == 0 && $this->width == 0 && $this->height == 0) {
         $this->width = $image->getWidth();
         $this->height = $image->getHeight();
     }
     $return_image = $image->crop($this->left, $this->top, $this->width, $this->height);
     return $return_image;
 }
Esempio n. 10
0
 /**
  * Returns a flipped image
  *
  * @param WideImage_Image $image
  * @return WideImage_Image
  */
 function execute($image)
 {
     $new = $image->copy();
     $width = $image->getWidth();
     $height = $image->getHeight();
     if ($new->isTransparent()) {
         imagefilledrectangle($new->getHandle(), 0, 0, $width, $height, $new->getTransparentColor());
     }
     for ($y = 0; $y < $height; $y++) {
         imagecopy($new->getHandle(), $image->getHandle(), 0, $y, 0, $height - $y - 1, $width, 1);
     }
     return $new;
 }
Esempio n. 11
0
 /**
  * Returns a mirrored image
  *
  * @param WideImage_Image $image
  * @return WideImage_Image
  */
 function execute($image)
 {
     $new = $image->copy();
     $width = $image->getWidth();
     $height = $image->getHeight();
     if ($new->isTransparent()) {
         imagefilledrectangle($new->getHandle(), 0, 0, $width, $height, $new->getTransparentColor());
     }
     for ($x = 0; $x < $width; $x++) {
         imagecopy($new->getHandle(), $image->getHandle(), $x, 0, $width - $x - 1, 0, 1, $height);
     }
     return $new;
 }
 /**
  * Executes imagefilter
  *
  * @param WideImage_Image $image
  * @param int $filter 
  * @param numeric $arg1
  * @param numeric $arg2
  * @param numeric $arg3
  * @return WideImage_TrueColorImage
  */
 function execute($image, $filter, $arg1 = null, $arg2 = null, $arg3 = null, $arg4 = null)
 {
     $new = $image->asTrueColor();
     if (in_array($filter, self::$one_arg_filters)) {
         imagefilter($new->getHandle(), $filter, $arg1);
     } elseif (defined('IMG_FILTER_PIXELATE') && $filter == IMG_FILTER_PIXELATE) {
         imagefilter($new->getHandle(), $filter, $arg1, $arg2);
     } elseif ($filter == IMG_FILTER_COLORIZE) {
         imagefilter($new->getHandle(), $filter, $arg1, $arg2, $arg3, $arg4);
     } else {
         imagefilter($new->getHandle(), $filter);
     }
     return $new;
 }
Esempio n. 13
0
 /**
  * Returns a flipped image.
  *
  * @param WideImage_Image $image
  *
  * @return WideImage_Image
  */
 public function execute($image)
 {
     $new = $image->copy();
     $width = $image->getWidth();
     $height = $image->getHeight();
     if ($new->isTransparent()) {
         imagefilledrectangle($new->getHandle(), 0, 0, $width, $height, $new->getTransparentColor());
     }
     for ($y = 0; $y < $height; ++$y) {
         if (!imagecopy($new->getHandle(), $image->getHandle(), 0, $y, 0, $height - $y - 1, $width, 1)) {
             throw new WideImage_GDFunctionResultException('imagecopy() returned false');
         }
     }
     return $new;
 }
Esempio n. 14
0
 /**
  * Returns a mirrored image
  *
  * @param WideImage_Image $image
  * @return WideImage_Image
  */
 function execute($image)
 {
     $new = $image->copy();
     $width = $image->getWidth();
     $height = $image->getHeight();
     if ($new->isTransparent()) {
         imagefilledrectangle($new->getHandle(), 0, 0, $width, $height, $new->getTransparentColor());
     }
     for ($x = 0; $x < $width; $x++) {
         if (!imagecopy($new->getHandle(), $image->getHandle(), $x, 0, $width - $x - 1, 0, 1, $height)) {
             throw new WideImage_GDFunctionResultException("imagecopy() returned false");
         }
     }
     return $new;
 }
Esempio n. 15
0
 public function rotate($angle, $bgColor = null, $ignoreTransparent = true)
 {
     if ((int) $angle !== 0) {
         $this->image = $this->image->rotate($angle, $bgColor, $ignoreTransparent);
     }
     return $this;
 }
Esempio n. 16
0
 /**
  * Returns a greyscale copy of an image
  *
  * @param WideImage_Image $image
  * @return WideImage_Image
  */
 function execute($image)
 {
     $palette = $image instanceof WideImage_PaletteImage;
     $transparent = $image->isTransparent();
     if ($palette && $transparent) {
         $tci = $image->getTransparentColor();
     }
     $new = $image->asTrueColor();
     imagefilter($new->getHandle(), IMG_FILTER_GRAYSCALE);
     if ($palette) {
         $new = $new->asPalette();
         if ($transparent) {
             $new->setTransparentColor($tci);
         }
     }
     return $new;
 }
Esempio n. 17
0
 /**
  * Executes imagefilter
  *
  * @param WideImage_Image $image
  * @param int $filter 
  * @param numeric $arg1
  * @param numeric $arg2
  * @param numeric $arg3
  * @return WideImage_TrueColorImage
  */
 function execute($image, $filter, $arg1 = null, $arg2 = null, $arg3 = null, $arg4 = null)
 {
     $new = $image->asTrueColor();
     if (in_array($filter, self::$one_arg_filters)) {
         $res = imagefilter($new->getHandle(), $filter, $arg1);
     } elseif (defined('IMG_FILTER_PIXELATE') && $filter == IMG_FILTER_PIXELATE) {
         $res = imagefilter($new->getHandle(), $filter, $arg1, $arg2);
     } elseif ($filter == IMG_FILTER_COLORIZE) {
         $res = imagefilter($new->getHandle(), $filter, $arg1, $arg2, $arg3, $arg4);
     } else {
         $res = imagefilter($new->getHandle(), $filter);
     }
     if (!$res) {
         throw new WideImage_GDFunctionResultException("imagefilter() returned false");
     }
     return $new;
 }
 /**
  * Prepares and corrects smart coordinates
  *
  * @param WideImage_Image $img
  * @param smart_coordinate $width
  * @param smart_coordinate $height
  * @param string $fit
  * @return array
  */
 protected function prepareDimensions($img, $width, $height, $fit)
 {
     if ($width === null && $height === null) {
         $width = $img->getWidth();
         $height = $img->getHeight();
     }
     if ($width !== null) {
         $width = WideImage_Coordinate::fix($width, $img->getWidth());
     }
     if ($height !== null) {
         $height = WideImage_Coordinate::fix($height, $img->getHeight());
     }
     if ($width === null) {
         $width = floor($img->getWidth() * $height / $img->getHeight());
     }
     if ($height === null) {
         $height = floor($img->getHeight() * $width / $img->getWidth());
     }
     if ($width === 0 || $height === 0) {
         return array('width' => 0, 'height' => 0);
     }
     if ($fit == null) {
         $fit = 'inside';
     }
     $dim = array();
     if ($fit == 'fill') {
         $dim['width'] = $width;
         $dim['height'] = $height;
     } elseif ($fit == 'inside' || $fit == 'outside') {
         $rx = $img->getWidth() / $width;
         $ry = $img->getHeight() / $height;
         if ($fit == 'inside') {
             $ratio = $rx > $ry ? $rx : $ry;
         } else {
             $ratio = $rx < $ry ? $rx : $ry;
         }
         $dim['width'] = round($img->getWidth() / $ratio);
         $dim['height'] = round($img->getHeight() / $ratio);
     } else {
         throw new WideImage_Operation_InvalidFitMethodException("{$fit} is not a valid resize-fit method.");
     }
     return $dim;
 }
Esempio n. 19
0
 /**
  * Returns rotated image
  *
  * @param WideImage_Image $image
  * @param numeric $angle
  * @param int $bgColor
  * @param bool $ignoreTransparent
  * @return WideImage_Image
  */
 function execute($image, $angle, $bgColor, $ignoreTransparent)
 {
     $angle = -floatval($angle);
     if ($angle < 0) {
         $angle = 360 + $angle;
     }
     $angle = $angle % 360;
     if ($angle == 0) {
         return $image->copy();
     }
     $image = $image->asTrueColor();
     if ($bgColor === null) {
         $bgColor = $image->getTransparentColor();
         if ($bgColor == -1) {
             $bgColor = $image->allocateColorAlpha(255, 255, 255, 127);
             imagecolortransparent($image->getHandle(), $bgColor);
         }
     }
     return new WideImage_TrueColorImage(imagerotate($image->getHandle(), $angle, $bgColor, $ignoreTransparent));
 }
Esempio n. 20
0
 /**
  * Returns a merged image
  *
  * @param WideImage_Image $base
  * @param WideImage_Image $overlay
  * @param smart_coordinate $left
  * @param smart_coordinate $top
  * @param numeric $pct
  * @return WideImage_Image
  */
 function execute($base, $overlay, $left, $top, $pct)
 {
     $x = WideImage_Coordinate::fix($left, $base->getWidth(), $overlay->getWidth());
     $y = WideImage_Coordinate::fix($top, $base->getHeight(), $overlay->getHeight());
     $result = $base->asTrueColor();
     $result->alphaBlending(true);
     $result->saveAlpha(true);
     if ($pct <= 0) {
         return $result;
     }
     if ($pct < 100) {
         imagecopymerge($result->getHandle(), $overlay->getHandle(), $x, $y, 0, 0, $overlay->getWidth(), $overlay->getHeight(), $pct);
     } else {
         imagecopy($result->getHandle(), $overlay->getHandle(), $x, $y, 0, 0, $overlay->getWidth(), $overlay->getHeight());
     }
     return $result;
 }
Esempio n. 21
0
 /**
  * Returns a mask
  *
  * @param WideImage_Image $image
  * @return WideImage_Image
  */
 function execute($image)
 {
     $width = $image->getWidth();
     $height = $image->getHeight();
     $mask = WideImage_TrueColorImage::create($width, $height);
     $mask->setTransparentColor(-1);
     $mask->alphaBlending(false);
     $mask->saveAlpha(false);
     for ($i = 0; $i <= 255; $i++) {
         $greyscale[$i] = ImageColorAllocate($mask->getHandle(), $i, $i, $i);
     }
     imagefilledrectangle($mask->getHandle(), 0, 0, $width, $height, $greyscale[255]);
     $transparentColor = $image->getTransparentColor();
     $alphaToGreyRatio = 255 / 127;
     for ($x = 0; $x < $width; $x++) {
         for ($y = 0; $y < $height; $y++) {
             $color = $image->getColorAt($x, $y);
             if ($color == $transparentColor) {
                 $rgba['alpha'] = 127;
             } else {
                 $rgba = $image->getColorRGB($color);
             }
             imagesetpixel($mask->getHandle(), $x, $y, $greyscale[255 - round($rgba['alpha'] * $alphaToGreyRatio)]);
         }
     }
     return $mask;
 }
Esempio n. 22
0
 /**
  * Returns a greyscale copy of an image
  *
  * @param WideImage_Image $image
  * @return WideImage_Image
  */
 function execute($image)
 {
     $palette = !$image->isTrueColor();
     $transparent = $image->isTransparent();
     if ($palette && $transparent) {
         $tcrgb = $image->getTransparentColorRGB();
     }
     $new = $image->asTrueColor();
     if (!imagefilter($new->getHandle(), IMG_FILTER_NEGATE)) {
         throw new WideImage_GDFunctionResultException("imagefilter() returned false");
     }
     if ($palette) {
         $new = $new->asPalette();
         if ($transparent) {
             $irgb = array('red' => 255 - $tcrgb['red'], 'green' => 255 - $tcrgb['green'], 'blue' => 255 - $tcrgb['blue'], 'alpha' => 127);
             // needs imagecolorexactalpha instead of imagecolorexact, otherwise doesn't work on some transparent GIF images
             $new_tci = imagecolorexactalpha($new->getHandle(), $irgb['red'], $irgb['green'], $irgb['blue'], 127);
             $new->setTransparentColor($new_tci);
         }
     }
     return $new;
 }
 /**
  * Returns an image with only specified channels copied
  * 
  * @param WideImage_Image $img
  * @param array $channels
  * @return WideImage_Image
  */
 function execute($img, $channels)
 {
     $blank = array('red' => 0, 'green' => 0, 'blue' => 0, 'alpha' => 0);
     $width = $img->getWidth();
     $height = $img->getHeight();
     $copy = WideImage_TrueColorImage::create($width, $height);
     if (count($channels) > 0) {
         for ($x = 0; $x < $width; $x++) {
             for ($y = 0; $y < $height; $y++) {
                 $RGBA = $img->getRGBAt($x, $y);
                 $newRGBA = $blank;
                 foreach ($channels as $channel) {
                     $newRGBA[$channel] = $RGBA[$channel];
                 }
                 $color = $copy->getExactColorAlpha($newRGBA);
                 if ($color == -1) {
                     $color = $copy->allocateColorAlpha($newRGBA);
                 }
                 $copy->setColorAt($x, $y, $color);
             }
         }
     }
     return $copy;
 }
Esempio n. 24
0
 /**
  * Returns a merged image.
  *
  * @param WideImage_Image  $base
  * @param WideImage_Image  $overlay
  * @param smart_coordinate $left
  * @param smart_coordinate $top
  * @param numeric          $pct
  *
  * @return WideImage_Image
  */
 public function execute($base, $overlay, $left, $top, $pct)
 {
     $x = WideImage_Coordinate::fix($left, $base->getWidth(), $overlay->getWidth());
     $y = WideImage_Coordinate::fix($top, $base->getHeight(), $overlay->getHeight());
     $result = $base->asTrueColor();
     $result->alphaBlending(true);
     $result->saveAlpha(true);
     if ($pct <= 0) {
         return $result;
     }
     if ($pct < 100) {
         if (!imagecopymerge($result->getHandle(), $overlay->getHandle(), $x, $y, 0, 0, $overlay->getWidth(), $overlay->getHeight(), $pct)) {
             throw new WideImage_GDFunctionResultException('imagecopymerge() returned false');
         }
     } else {
         if (!imagecopy($result->getHandle(), $overlay->getHandle(), $x, $y, 0, 0, $overlay->getWidth(), $overlay->getHeight())) {
             throw new WideImage_GDFunctionResultException('imagecopy() returned false');
         }
     }
     return $result;
 }
Esempio n. 25
0
 /**
  * Applies a mask on the copy of source image
  *
  * @param WideImage_Image $image
  * @param WideImage_Image $mask
  * @param smart_coordinate $left
  * @param smart_coordinate $top
  * @return WideImage_Image
  */
 function execute($image, $mask, $left = 0, $top = 0)
 {
     $left = WideImage_Coordinate::fix($image->getWidth(), $left);
     $top = WideImage_Coordinate::fix($image->getHeight(), $top);
     $width = $image->getWidth();
     if ($width > $mask->getWidth()) {
         $width = $mask->getWidth();
     }
     $height = $image->getHeight();
     if ($height > $mask->getHeight()) {
         $height = $mask->getHeight();
     }
     $result = $image->asTrueColor();
     $result->alphaBlending(false);
     $result->saveAlpha(true);
     $srcTransparentColor = $image->getTransparentColor();
     if ($srcTransparentColor >= 0) {
         $trgb = $image->getColorRGB($srcTransparentColor);
         $trgb['alpha'] = 127;
         $destTransparentColor = $result->allocateColorAlpha($trgb);
         $result->setTransparentColor($destTransparentColor);
     } else {
         $destTransparentColor = $result->allocateColorAlpha(255, 255, 255, 127);
     }
     for ($x = 0; $x < $width; $x++) {
         for ($y = 0; $y < $height; $y++) {
             if ($left + $x < $image->getWidth() && $top + $y < $image->getHeight()) {
                 $srcColor = $image->getColorAt($left + $x, $top + $y);
                 if ($srcColor == $srcTransparentColor) {
                     $destColor = $destTransparentColor;
                 } else {
                     $maskRGB = $mask->getRGBAt($x, $y);
                     if ($maskRGB['red'] == 0) {
                         $destColor = $destTransparentColor;
                     } elseif ($srcColor >= 0) {
                         $imageRGB = $image->getRGBAt($left + $x, $top + $y);
                         $level = $maskRGB['red'] / 255 * (1 - $imageRGB['alpha'] / 127);
                         $imageRGB['alpha'] = 127 - round($level * 127);
                         if ($imageRGB['alpha'] == 127) {
                             $destColor = $destTransparentColor;
                         } else {
                             $destColor = $result->allocateColorAlpha($imageRGB);
                         }
                     } else {
                         $destColor = $destTransparentColor;
                     }
                 }
                 $result->setColorAt($left + $x, $top + $y, $destColor);
             }
         }
     }
     return $result;
 }
Esempio n. 26
0
 /**
  * Applies a mask on the copy of source image
  *
  * @param WideImage_Image $image
  * @param WideImage_Image $mask
  * @param smart_coordinate $left
  * @param smart_coordinate $top
  * @return WideImage_Image
  */
 function execute($image, $mask, $left = 0, $top = 0)
 {
     $left = WideImage_Coordinate::fix($left, $image->getWidth(), $mask->getWidth());
     $top = WideImage_Coordinate::fix($top, $image->getHeight(), $mask->getHeight());
     $width = $image->getWidth();
     $mask_width = $mask->getWidth();
     $height = $image->getHeight();
     $mask_height = $mask->getHeight();
     $result = $image->asTrueColor();
     $result->alphaBlending(false);
     $result->saveAlpha(true);
     $srcTransparentColor = $result->getTransparentColor();
     if ($srcTransparentColor >= 0) {
         # this was here. works without.
         #$trgb = $image->getColorRGB($srcTransparentColor);
         #$trgb['alpha'] = 127;
         #$destTransparentColor = $result->allocateColorAlpha($trgb);
         #$result->setTransparentColor($destTransparentColor);
         $destTransparentColor = $srcTransparentColor;
     } else {
         $destTransparentColor = $result->allocateColorAlpha(255, 255, 255, 127);
     }
     for ($x = 0; $x < $width; $x++) {
         for ($y = 0; $y < $height; $y++) {
             $mx = $x - $left;
             $my = $y - $top;
             if ($mx >= 0 && $mx < $mask_width && $my >= 0 && $my < $mask_height) {
                 $srcColor = $image->getColorAt($x, $y);
                 if ($srcColor == $srcTransparentColor) {
                     $destColor = $destTransparentColor;
                 } else {
                     $maskRGB = $mask->getRGBAt($mx, $my);
                     if ($maskRGB['red'] == 0) {
                         $destColor = $destTransparentColor;
                     } elseif ($srcColor >= 0) {
                         $imageRGB = $image->getRGBAt($x, $y);
                         $level = $maskRGB['red'] / 255 * (1 - $imageRGB['alpha'] / 127);
                         $imageRGB['alpha'] = 127 - round($level * 127);
                         if ($imageRGB['alpha'] == 127) {
                             $destColor = $destTransparentColor;
                         } else {
                             $destColor = $result->allocateColorAlpha($imageRGB);
                         }
                     } else {
                         $destColor = $destTransparentColor;
                     }
                 }
                 $result->setColorAt($x, $y, $destColor);
             }
         }
     }
     return $result;
 }
Esempio n. 27
0
 /**
  * Returns image with every pixel changed by specififed function
  *
  * @param WideImage_Image $image
  * @param str $function
  * @param int $value
  * @return WideImage_Image
  */
 function filter($image, $function, $value)
 {
     for ($y = 0; $y < $image->getHeight(); $y++) {
         for ($x = 0; $x < $image->getWidth(); $x++) {
             $rgb = imagecolorat($image->getHandle(), $x, $y);
             $a = $rgb >> 24 & 0xff;
             $r = $rgb >> 16 & 0xff;
             $g = $rgb >> 8 & 0xff;
             $b = $rgb & 0xff;
             self::$function($r, $g, $b, $value);
             $color = imagecolorallocatealpha($image->getHandle(), $r, $g, $b, $a);
             imagesetpixel($image->getHandle(), $x, $y, $color);
         }
     }
     return $image;
 }
Esempio n. 28
0
 /**
  * Writes text onto an image.
  *
  * @param WideImage_Image $image
  * @param mixed           $x     smart coordinate
  * @param mixed           $y     smart coordinate
  * @param string          $text
  * @param int             $angle Angle in degrees clockwise
  */
 public function writeText($image, $x, $y, $text, $angle = 0)
 {
     if ($image->isTrueColor()) {
         $image->alphaBlending(true);
     }
     $box = imageftbbox($this->size, $angle, $this->face, $text);
     $obox = ['left' => min($box[0], $box[2], $box[4], $box[6]), 'top' => min($box[1], $box[3], $box[5], $box[7]), 'right' => max($box[0], $box[2], $box[4], $box[6]) - 1, 'bottom' => max($box[1], $box[3], $box[5], $box[7]) - 1];
     $obox['width'] = abs($obox['left']) + abs($obox['right']);
     $obox['height'] = abs($obox['top']) + abs($obox['bottom']);
     $x = WideImage_Coordinate::fix($x, $image->getWidth(), $obox['width']);
     $y = WideImage_Coordinate::fix($y, $image->getHeight(), $obox['height']);
     $fixed_x = $x - $obox['left'];
     $fixed_y = $y - $obox['top'];
     imagettftext($image->getHandle(), $this->size, $angle, $fixed_x, $fixed_y, $this->color, $this->face, $text);
 }
Esempio n. 29
0
 /**
  * Returns sharpened image
  *
  * @param WideImage_Image $image
  * @param float $amount
  * @param int $radius
  * @param float $threshold
  * @return WideImage_Image
  */
 function execute($image, $amount, $radius, $threshold)
 {
     // Attempt to calibrate the parameters to Photoshop:
     if ($amount > 500) {
         $amount = 500;
     }
     $amount = $amount * 0.016;
     if ($radius > 50) {
         $radius = 50;
     }
     $radius = $radius * 2;
     if ($threshold > 255) {
         $threshold = 255;
     }
     $radius = abs(round($radius));
     // Only integers make sense.
     if ($radius == 0) {
         return $image;
     }
     // Gaussian blur matrix
     $matrix = array(array(1, 2, 1), array(2, 4, 2), array(1, 2, 1));
     $blurred = $image->applyConvolution($matrix, 16, 0);
     if ($threshold > 0) {
         // Calculate the difference between the blurred pixels and the original
         // and set the pixels
         for ($x = 0; $x < $image->getWidth(); $x++) {
             for ($y = 0; $y < $image->getHeight(); $y++) {
                 $rgbOrig = $image->getRGBAt($x, $y);
                 $rOrig = $rgbOrig["red"];
                 $gOrig = $rgbOrig["green"];
                 $bOrig = $rgbOrig["blue"];
                 $rgbBlur = $blurred->getRGBAt($x, $y);
                 $rBlur = $rgbBlur["red"];
                 $gBlur = $rgbBlur["green"];
                 $bBlur = $rgbBlur["blue"];
                 // When the masked pixels differ less from the original
                 // than the threshold specifies, they are set to their original value.
                 $rNew = abs($rOrig - $rBlur) >= $threshold ? max(0, min(255, $amount * ($rOrig - $rBlur) + $rOrig)) : $rOrig;
                 $gNew = abs($gOrig - $gBlur) >= $threshold ? max(0, min(255, $amount * ($gOrig - $gBlur) + $gOrig)) : $gOrig;
                 $bNew = abs($bOrig - $bBlur) >= $threshold ? max(0, min(255, $amount * ($bOrig - $bBlur) + $bOrig)) : $bOrig;
                 $rgbNew = array("red" => $rNew, "green" => $gNew, "blue" => $bNew, "alpha" => 0);
                 if ($rOrig != $rNew || $gOrig != $gNew || $bOrig != $bNew) {
                     $image->setRGBAt($x, $y, $rgbNew);
                 }
             }
         }
     } else {
         $w = $image->getWidth();
         $h = $image->getHeight();
         for ($x = 0; $x < $w; $x++) {
             for ($y = 0; $y < $h; $y++) {
                 $rgbOrig = $image->getRGBAt($x, $y);
                 $rOrig = $rgbOrig["red"];
                 $gOrig = $rgbOrig["green"];
                 $bOrig = $rgbOrig["blue"];
                 $rgbBlur = $blurred->getRGBAt($x, $y);
                 $rBlur = $rgbBlur["red"];
                 $gBlur = $rgbBlur["green"];
                 $bBlur = $rgbBlur["blue"];
                 $rNew = $amount * ($rOrig - $rBlur) + $rOrig;
                 if ($rNew > 255) {
                     $rNew = 255;
                 } elseif ($rNew < 0) {
                     $rNew = 0;
                 }
                 $gNew = $amount * ($gOrig - $gBlur) + $gOrig;
                 if ($gNew > 255) {
                     $gNew = 255;
                 } elseif ($gNew < 0) {
                     $gNew = 0;
                 }
                 $bNew = $amount * ($bOrig - $bBlur) + $bOrig;
                 if ($bNew > 255) {
                     $bNew = 255;
                 } elseif ($bNew < 0) {
                     $bNew = 0;
                 }
                 $rgbNew = array("red" => $rNew, "green" => $gNew, "blue" => $bNew, "alpha" => 0);
                 $image->setRGBAt($x, $y, $rgbNew);
             }
         }
     }
     return $image;
 }
Esempio n. 30
0
 /**
  * Fix a coordinate for a resize (limits by image weight and height)
  * 
  * @param WideImage_Image $img
  * @param int $width Width of the image
  * @param int $height Height of the image
  * @return array An array(width, height), fixed for resizing
  */
 static function fixForResize($img, $width, $height)
 {
     if ($width === null && $height === null) {
         return array($img->getWidth(), $img->getHeight());
     }
     if ($width !== null) {
         $width = self::fix($width, $img->getWidth());
     }
     if ($height !== null) {
         $height = self::fix($height, $img->getHeight());
     }
     if ($width === null) {
         $width = floor($img->getWidth() * $height / $img->getHeight());
     }
     if ($height === null) {
         $height = floor($img->getHeight() * $width / $img->getWidth());
     }
     return array($width, $height);
 }