Beispiel #1
0
 /**
  * Apply given image as alpha mask on current image
  *
  * @param  mixed   $source
  * @param  boolean $mask_with_alpha
  * @return Image
  */
 public function mask($source, $mask_with_alpha = false)
 {
     // create new empty image
     $maskedImage = new Image(null, $this->width, $this->height);
     // create mask
     $mask = is_a($source, 'Intervention\\Image\\Image') ? $source : new Image($source);
     // resize mask to size of current image (if necessary)
     if ($mask->width != $this->width || $mask->height != $this->height) {
         $mask->resize($this->width, $this->height);
     }
     // redraw old image pixel by pixel considering alpha map
     for ($x = 0; $x < $this->width; $x++) {
         for ($y = 0; $y < $this->height; $y++) {
             $color = $this->pickColor($x, $y, 'array');
             $alpha = $mask->pickColor($x, $y, 'array');
             if ($mask_with_alpha) {
                 $alpha = $alpha['a'];
                 // use alpha channel as mask
             } else {
                 $alpha = floatval(round($alpha['r'] / 255, 2));
                 // use red channel as mask
             }
             // preserve alpha of original image...
             if ($color['a'] < $alpha) {
                 $alpha = $color['a'];
             }
             $pixelColor = array($color['r'], $color['g'], $color['b'], $alpha);
             $maskedImage->pixel($pixelColor, $x, $y);
         }
     }
     // apply masked image to current instance
     $this->resource = $maskedImage->resource;
     $this->width = $maskedImage->width;
     $this->height = $maskedImage->height;
     return $this;
 }
Beispiel #2
0
 /**
  * Set single pixel
  *
  * @param string $color
  * @param integer $pos_x
  * @param integer $pos_y
  * @return \Intervention\Image\Image 
  * @static 
  */
 public static function pixel($color, $pos_x = 0, $pos_y = 0)
 {
     return \Intervention\Image\Image::pixel($color, $pos_x, $pos_y);
 }