コード例 #1
0
 /**
  * Applies the filter to the image resource
  *
  * @param ImageResource $aResource
  */
 public function applyFilter(ImageResource $aResource)
 {
     if ($this->percentage == 0) {
         return;
         // percentage = 0, do nothing !
     }
     $resource = $aResource->getResource();
     $rgb = 0;
     $d = array();
     $s = array();
     $dstx = 0;
     $dsty = 0;
     $dest = imagecreatetruecolor($aResource->getX(), $aResource->getY());
     for ($i = 0; $i < $aResource->getY(); $i++) {
         for ($j = 0; $j < $aResource->getX(); $j++) {
             $rgb = imagecolorat($dest, $dstx + $j, $dsty + $i);
             $d[0] = $rgb >> 16 & 0xff;
             $d[1] = $rgb >> 8 & 0xff;
             $d[2] = $rgb & 0xff;
             $rgb = imagecolorat($aResource->getResource(), $j, $i);
             $s[0] = $rgb >> 16 & 0xff;
             $s[1] = $rgb >> 8 & 0xff;
             $s[2] = $rgb & 0xff;
             $d[0] += min($s[0], 0xff - $d[0]) * $this->percentage / 100;
             $d[1] += min($s[1], 0xff - $d[1]) * $this->percentage / 100;
             $d[2] += min($s[2], 0xff - $d[2]) * $this->percentage / 100;
             imagesetpixel($resource, $dstx + $j, $dsty + $i, imagecolorallocate($resource, $d[0], $d[1], $d[2]));
         }
     }
 }
コード例 #2
0
 /**
  * (non-PHPdoc)
  * @see \imagemanipulation\filter\IImageFilter::applyFilter()
  */
 public function applyFilter(ImageResource $aResource)
 {
     $placeholder = imagecreatetruecolor($aResource->getX(), $aResource->getY());
     imagealphablending($placeholder, false);
     imagesavealpha($placeholder, true);
     $destWidth = $this->fill ? $aResource->getX() : $this->overlay->getX();
     $destHeight = $this->fill ? $aResource->getY() : $this->overlay->getY();
     imagecopyresized($placeholder, $this->overlay->getResource(), 0, 0, 0, 0, $destWidth, $destHeight, $this->overlay->getX(), $this->overlay->getY());
     imagecopymerge($aResource->getResource(), $placeholder, $this->startX, $this->startY, 0, 0, $destWidth, $destHeight, $this->opacity);
 }
コード例 #3
0
 /**
  * Applies the filter to the image resource
  *
  * @param ImageResource $aResource
  */
 public function applyFilter(ImageResource $aResource)
 {
     if ($this->angle == 0 || $this->angle == 360) {
         return;
     }
     imageantialias($aResource->getResource(), true);
     $aResource->setResource(imagerotate($aResource->getResource(), $this->angle, $this->bgColor->getColorIndex(), $this->bgColor->getAlpha()));
     $new_imgres = imagecreatetruecolor($aResource->getX(), $aResource->getY());
     $success = imagecopy($new_imgres, $aResource->getResource(), 0, 0, 0, 0, $aResource->getX(), $aResource->getY());
     if (!$success) {
         throw new FilterException(self::$filterType);
     }
     imagedestroy($new_imgres);
 }
コード例 #4
0
 /**
  * (non-PHPdoc)
  * @see \imagemanipulation\filter\IImageFilter::applyFilter()
  */
 public function applyFilter(ImageResource $resource)
 {
     if ($this->radius === 0) {
         return;
     }
     $source_image = $resource->getResource();
     $source_width = $resource->getX();
     $source_height = $resource->getY();
     $corner_image = imagecreatetruecolor($this->radius, $this->radius);
     $clear_colour = imagecolorallocate($corner_image, 0, 0, 0);
     imagecolortransparent($corner_image, $clear_colour);
     $solid_colour = imagecolorallocate($corner_image, $this->color->getRed(), $this->color->getGreen(), $this->color->getBlue());
     imagefill($corner_image, 0, 0, $solid_colour);
     imagefilledellipse($corner_image, $this->radius, $this->radius, $this->radius * 2, $this->radius * 2, $clear_colour);
     /*
      * render the top-left, bottom-left, bottom-right, top-right corners by rotating and copying the mask
      */
     imagecopymerge($source_image, $corner_image, 0, 0, 0, 0, $this->radius, $this->radius, 100);
     $corner_image = imagerotate($corner_image, 90, 0);
     imagecopymerge($source_image, $corner_image, 0, $source_height - $this->radius, 0, 0, $this->radius, $this->radius, 100);
     $corner_image = imagerotate($corner_image, 90, 0);
     imagecopymerge($source_image, $corner_image, $source_width - $this->radius, $source_height - $this->radius, 0, 0, $this->radius, $this->radius, 100);
     $corner_image = imagerotate($corner_image, 90, 0);
     imagecopymerge($source_image, $corner_image, $source_width - $this->radius, 0, 0, 0, $this->radius, $this->radius, 100);
 }
コード例 #5
0
 /**
  * (non-PHPdoc)
  * @see \imagemanipulation\filter\IImageFilter::applyFilter()
  */
 public function applyFilter(ImageResource $aResource)
 {
     $watermarkRes = new ImageImageResource($this->watermark);
     imagealphablending($aResource->getResource(), true);
     imagealphablending($watermarkRes->getResource(), true);
     if ($this->position == 'random') {
         $this->position = rand(1, 8);
     }
     if ($this->watermarkOpacity) {
         $opacityFilter = new ImageFilterOpacity($this->watermarkOpacity);
         $opacityFilter->applyFilter($watermarkRes);
     }
     $destWidth = $aResource->getX();
     $destHeight = $aResource->getY();
     $watermarkWidth = $watermarkRes->getX();
     $watermarkHeight = $watermarkRes->getY();
     switch ($this->position) {
         case 'top-right':
         case 'right-top':
         case 1:
             $result = imagecopy($aResource->getResource(), $watermarkRes->getResource(), $destWidth - $watermarkWidth, 0, 0, 0, $watermarkWidth, $watermarkHeight);
             break;
         case 'top-left':
         case 2:
             $result = imagecopy($aResource->getResource(), $watermarkRes->getResource(), 0, 0, 0, 0, $watermarkWidth, $watermarkHeight);
             break;
         case 'bottom-right':
         case 3:
             $result = imagecopy($aResource->getResource(), $watermarkRes->getResource(), $destWidth - $watermarkWidth, $destHeight - $watermarkHeight, 0, 0, $watermarkWidth, $watermarkHeight);
             break;
         case 'bottom-left':
         case 4:
             $result = imagecopy($aResource->getResource(), $watermarkRes->getResource(), 0, $destHeight - $watermarkHeight, 0, 0, $watermarkWidth, $watermarkHeight);
             break;
         case 'center':
         case 5:
             $result = imagecopy($aResource->getResource(), $watermarkRes->getResource(), $destWidth / 2 - $watermarkWidth / 2, $destHeight / 2 - $watermarkHeight / 2, 0, 0, $watermarkWidth, $watermarkHeight);
             break;
         case 'top':
         case 6:
             $result = imagecopy($aResource->getResource(), $watermarkRes->getResource(), $destWidth / 2 - $watermarkWidth / 2, 0, 0, 0, $watermarkWidth, $watermarkHeight);
             break;
         case 'bottom':
         case 7:
             $result = imagecopy($aResource->getResource(), $watermarkRes->getResource(), $destWidth / 2 - $watermarkWidth / 2, $destHeight - $watermarkHeight, 0, 0, $watermarkWidth, $watermarkHeight);
             break;
         case 'left':
         case 8:
             $result = imagecopy($aResource->getResource(), $watermarkRes->getResource(), 0, $destHeight / 2 - $watermarkHeight / 2, 0, 0, $watermarkWidth, $watermarkHeight);
             break;
         case 'right':
         case 9:
             $result = imagecopy($aResource->getResource(), $watermarkRes->getResource(), $destWidth - $watermarkWidth, $destHeight / 2 - $watermarkHeight / 2, 0, 0, $watermarkWidth, $watermarkHeight);
             break;
             imagedestroy($watermarkRes->getResource());
             if (!$result) {
                 throw new \Exception('Applying watermark failed');
             }
     }
 }
コード例 #6
0
 /**
  * Applies the filter to the image resource
  *
  * @param ImageResource $aResource
  */
 public function applyFilter(ImageResource $aResource)
 {
     $function = 'imageflip';
     if (function_exists($function)) {
         $function($aResource->getResource(), $this->getMode());
     } else {
         $width = $aResource->getX();
         $height = $aResource->getY();
         $dest = imagecreatetruecolor($width, $height);
         imagealphablending($dest, false);
         imagesavealpha($dest, true);
         switch ($this->getMode()) {
             case self::FLIP_VERTICALLY:
                 $this->flipVertically($dest, $aResource->getResource(), $height, $width);
                 break;
             case self::FLIP_HORIZONTALLY:
                 $this->flipHorizontally($dest, $aResource->getResource(), $height, $width);
                 break;
             case self::FLIP_BOTH:
                 $this->flipVertically($dest, $aResource->getResource(), $height, $width);
                 $copy = imagecreatetruecolor($width, $height);
                 imagecopy($copy, $dest, 0, 0, 0, 0, $width, $height);
                 $this->flipHorizontally($dest, $copy, $height, $width);
                 break;
         }
         $aResource->setResource($dest);
     }
 }
コード例 #7
0
 /**
  * Applies the sepia filter to an image resource
  *
  * @param ImageResource $aResource
  */
 public function applyFilter(ImageResource $aResource)
 {
     if ($this->degrees === 0) {
         return;
     }
     $width = $aResource->getX();
     $height = $aResource->getY();
     // cache calculated colors in a map...
     $colorMap = array();
     for ($x = 0; $x < $width; ++$x) {
         for ($y = 0; $y < $height; ++$y) {
             $color = ColorUtil::getColorAt($aResource, Coordinate::create($x, $y));
             if (!isset($colorMap[$color->getColorIndex()])) {
                 // calculate the new color
                 $hsl = ColorUtil::rgb2hsl($color->getRed(), $color->getGreen(), $color->getBlue());
                 $hsl[0] += $this->degrees;
                 $rgb = ColorUtil::hsl2rgb($hsl[0], $hsl[1], $hsl[2]);
                 $newcol = imagecolorallocate($aResource->getResource(), $rgb[0], $rgb[1], $rgb[2]);
                 $colorMap[$color->getColorIndex()] = $newcol;
             } else {
                 $newcol = $colorMap[$color->getColorIndex()];
             }
             imagesetpixel($aResource->getResource(), $x, $y, $newcol);
         }
     }
     $colorMap = null;
 }
コード例 #8
0
 /**
  * Applies the filter to the resource
  *
  * @param ImageResource $aResource
  */
 public function applyFilter(ImageResource $aResource)
 {
     $width = $aResource->getX();
     $height = $aResource->getY();
     $lineRes = imagecreatetruecolor($width, 1);
     $bgc = imagecolorallocatealpha($lineRes, $this->backgroundColor->getRed(), $this->backgroundColor->getGreen(), $this->backgroundColor->getBlue(), $this->backgroundColor->getAlpha());
     // Background color
     imagefilledrectangle($lineRes, 0, 0, $width, 1, $bgc);
     $rotateFilter = new ImageFilterRotate(180, $this->backgroundColor);
     $rotateFilter->applyFilter($aResource);
     $bg = imagecreatetruecolor($width, $this->height);
     imagecopyresampled($bg, $aResource->getResource(), 0, 0, 0, 0, $width, $height, $width, $height);
     $im = $bg;
     $bg = imagecreatetruecolor($width, $this->height);
     for ($x = 0; $x < $width; $x++) {
         imagecopy($bg, $im, $x, 0, $width - $x, 0, 1, $this->height);
     }
     $im = $bg;
     $in = 100 / $this->height;
     for ($i = 0; $i <= $this->height; $i++) {
         imagecopymerge($im, $lineRes, 0, $i, 0, 0, $width, 1, $this->startOpacity);
         if ($this->startOpacity < 100) {
             $this->startOpacity += $in;
         }
     }
     imagecopymerge($im, $lineRes, 0, 0, 0, 0, $width, $this->divLineHeight, 100);
     // Divider
     $aResource->setResource($im);
 }
コード例 #9
0
 /**
  * Applies the sepia filter to an image resource
  *
  * @param ImageResource $aResource
  */
 public function applyFilter(ImageResource $aResource)
 {
     $dstImg = $aResource->getResource();
     $imgX = $aResource->getX();
     $imgY = $aResource->getY();
     $previous = array("index" => -1, "result" => 0);
     for ($y = 0; $y < $imgY; $y++) {
         for ($x = 0; $x < $imgX; $x++) {
             $dstRGB = imagecolorat($dstImg, $x, $y);
             if ($previous["index"] === $dstRGB) {
                 $newRGB = $previous["result"];
             } else {
                 $dstR = $dstRGB >> 16 & 0xff;
                 $dstG = $dstRGB >> 8 & 0xff;
                 $dstB = $dstRGB & 0xff;
                 $newR = $dstR * 0.393 + $dstG * 0.769 + $dstB * 0.189 - $this->darken;
                 $newG = $dstR * 0.349 + $dstG * 0.6860000000000001 + $dstB * 0.168 - $this->darken;
                 $newB = $dstR * 0.272 + $dstG * 0.534 + $dstB * 0.131 - $this->darken;
                 $newR = $newR > 255 ? 255 : ($newR < 0 ? 0 : $newR);
                 $newG = $newG > 255 ? 255 : ($newG < 0 ? 0 : $newG);
                 $newB = $newB > 255 ? 255 : ($newB < 0 ? 0 : $newB);
                 $newRGB = imagecolorallocate($dstImg, $newR, $newG, $newB);
                 $previous["index"] = $dstRGB;
                 $previous["result"] = $newRGB;
             }
             imagesetpixel($dstImg, $x, $y, $newRGB);
         }
     }
 }
コード例 #10
0
 /**
  * Calculates the average color of an image.
  * 
  * @param ImageResource $aResource
  * 
  * @return IColor
  */
 public static function average(ImageResource $aResource)
 {
     $w = $aResource->getX();
     $h = $aResource->getY();
     $r = $g = $b = 0;
     $res = $aResource->getResource();
     for ($y = 0; $y < $h; $y++) {
         for ($x = 0; $x < $w; $x++) {
             $rgb = imagecolorat($res, $x, $y);
             $r += $rgb >> 16;
             $g += $rgb >> 8 & 255;
             $b += $rgb & 255;
         }
     }
     $pxls = $w * $h;
     $r = dechex(round($r / $pxls));
     $g = dechex(round($g / $pxls));
     $b = dechex(round($b / $pxls));
     if (strlen($r) < 2) {
         $r = 0 . $r;
     }
     if (strlen($g) < 2) {
         $g = 0 . $g;
     }
     if (strlen($b) < 2) {
         $b = 0 . $b;
     }
     $index = Color::createColorIndex($r, $g, $b);
     return new Color($index);
 }
コード例 #11
0
 public function applyFilter(ImageResource $aResource)
 {
     $x = $aResource->getX();
     $y = $aResource->getY();
     $resource = $aResource->getResource();
     // Create a new image
     $ip = imagecreatetruecolor($x, $y);
     // Loop through the whole height of the image
     for ($i = 0; $i < $y; $i++) {
         // Loop through the whole width of the image
         for ($j = 0; $j < $x; $j++) {
             // Get the pixel color ( $this->img->x - 1 needs to be there because of the imagestart @ 0,0 ;) )
             $c = imagecolorat($resource, $x - 1 - $j, $i);
             // Get the rgb values from color $c
             $r = $c >> 16 & 0xff;
             $g = $c >> 8 & 0xff;
             $b = $c & 0xff;
             // Set the color
             $clr = imagecolorallocate($ip, $r, $g, $b);
             // Set the pixel color in the new image
             imagesetpixel($ip, $j, $i, $clr);
         }
     }
     $aResource->setResource(imagecreatetruecolor($x, $y));
     imagecopy($aResource->getResource(), $ip, 0, 0, 0, 0, $x, $y);
 }
コード例 #12
0
 /**
  * (non-PHPdoc)
  * @see \imagemanipulation\filter\IImageFilter::applyFilter()
  */
 public function applyFilter(ImageResource $aResource)
 {
     $resource = $aResource->getResource();
     $imagex = $aResource->getX();
     $imagey = $aResource->getY();
     for ($x = 0; $x < $imagex; $x += $this->blocksize) {
         for ($y = 0; $y < $imagey; $y += $this->blocksize) {
             // get the pixel colour at the top-left of the square
             $thiscol = imagecolorat($resource, $x, $y);
             // set the new red, green, and blue values to 0
             $newr = 0;
             $newg = 0;
             $newb = 0;
             // create an empty array for the colours
             $colours = array();
             // cycle through each pixel in the block
             for ($k = $x; $k < $x + $this->blocksize; ++$k) {
                 for ($l = $y; $l < $y + $this->blocksize; ++$l) {
                     // if we are outside the valid bounds of the image, use a safe colour
                     if ($k < 0) {
                         $colours[] = $thiscol;
                         continue;
                     }
                     if ($k >= $imagex) {
                         $colours[] = $thiscol;
                         continue;
                     }
                     if ($l < 0) {
                         $colours[] = $thiscol;
                         continue;
                     }
                     if ($l >= $imagey) {
                         $colours[] = $thiscol;
                         continue;
                     }
                     // if not outside the image bounds, get the colour at this pixel
                     $colours[] = imagecolorat($resource, $k, $l);
                 }
             }
             // cycle through all the colours we can use for sampling
             foreach ($colours as $colour) {
                 // add their red, green, and blue values to our master numbers
                 $newr += $colour >> 16 & 0xff;
                 $newg += $colour >> 8 & 0xff;
                 $newb += $colour & 0xff;
             }
             // now divide the master numbers by the number of valid samples to get an average
             $numelements = count($colours);
             $newr /= $numelements;
             $newg /= $numelements;
             $newb /= $numelements;
             // and use the new numbers as our colour
             $newcol = imagecolorallocate($resource, $newr, $newg, $newb);
             imagefilledrectangle($resource, $x, $y, $x + $this->blocksize - 1, $y + $this->blocksize - 1, $newcol);
         }
     }
 }
コード例 #13
0
 /**
  * Applies the filter to the resource
  *
  * @param ImageResource $aResource
  */
 public function applyFilter(ImageResource $aResource)
 {
     $orig_time_limit = ini_get('max_execution_time');
     set_time_limit(180);
     // creating the image
     $starting_img = $aResource->getResource();
     // this will be the final image, same width and height of the original
     $final = imagecreatetruecolor($aResource->getX(), $aResource->getY());
     // looping through ALL pixels!!
     for ($x = 1; $x < $aResource->getX() - 1; $x++) {
         for ($y = 1; $y < $aResource->getY() - 1; $y++) {
             // getting gray value of all surrounding pixels
             $pixel_up = $this->getLuminance(imagecolorat($starting_img, $x, $y - 1));
             $pixel_down = $this->getLuminance(imagecolorat($starting_img, $x, $y + 1));
             $pixel_left = $this->getLuminance(imagecolorat($starting_img, $x - 1, $y));
             $pixel_right = $this->getLuminance(imagecolorat($starting_img, $x + 1, $y));
             $pixel_up_left = $this->getLuminance(imagecolorat($starting_img, $x - 1, $y - 1));
             $pixel_up_right = $this->getLuminance(imagecolorat($starting_img, $x + 1, $y - 1));
             $pixel_down_left = $this->getLuminance(imagecolorat($starting_img, $x - 1, $y + 1));
             $pixel_down_right = $this->getLuminance(imagecolorat($starting_img, $x + 1, $y + 1));
             // appliying convolution mask
             $conv_x = $pixel_up_right + $pixel_right * 2 + $pixel_down_right - ($pixel_up_left + $pixel_left * 2 + $pixel_down_left);
             $conv_y = $pixel_up_left + $pixel_up * 2 + $pixel_up_right - ($pixel_down_left + $pixel_down * 2 + $pixel_down_right);
             // calculating the distance
             $gray = (int) sqrt($conv_x * $conv_x + $conv_y + $conv_y);
             // inverting the distance not to get the negative image
             $gray = 255 - $gray;
             // adjusting distance if it's greater than 255 or less than zero (out of color range)
             if ($gray > 255) {
                 $gray = 255;
             }
             if ($gray < 0) {
                 $gray = 0;
             }
             // creation of the new gray
             $new_gray = imagecolorallocate($final, $gray, $gray, $gray);
             // adding the gray pixel to the new image
             imagesetpixel($final, $x, $y, $new_gray);
         }
     }
     imagedestroy($starting_img);
     $aResource->setResource($final);
     set_time_limit($orig_time_limit);
 }
コード例 #14
0
 /**
  * (non-PHPdoc)
  * @see \imagemanipulation\filter\IImageFilter::applyFilter()
  */
 public function applyFilter(ImageResource $aResource)
 {
     $destWidth = $this->fill ? $aResource->getX() : $this->overlay->getX();
     $destHeight = $this->fill ? $aResource->getY() : $this->overlay->getY();
     imagealphablending($this->overlay->getResource(), false);
     imagesavealpha($this->overlay->getResource(), false);
     imagecopyresized($this->overlay->getResource(), $this->overlay->getResource(), 0, 0, 0, 0, $destWidth, $destHeight, $this->overlay->getX(), $this->overlay->getY());
     imagealphablending($aResource->getResource(), true);
     imagesavealpha($aResource->getResource(), true);
     imagecopyresampled($aResource->getResource(), $this->overlay->getResource(), $this->startX, $this->startY, 0, 0, $destWidth, $destHeight, $destWidth, $destHeight);
 }
コード例 #15
0
 /**
  * Applies the filter to the resource
  *
  * @param ImageResource $aResource
  */
 public function applyFilter(ImageResource $aResource)
 {
     $width = $aResource->getX();
     $height = $aResource->getY();
     $blockImg = imagecreate(1, 1);
     imagecolorallocatealpha($blockImg, $this->blockColor->getRed(), $this->blockColor->getGreen(), $this->blockColor->getBlue(), $this->blockColor->getAlpha());
     for ($i = 0; $i <= $this->nrOfBlocks; $i++) {
         $xPos = rand(0, $width - $this->blockSize - 1);
         $yPos = rand(0, $height - $this->blockSize - 1);
         imagecopy($aResource->getResource(), $blockImg, $xPos, $yPos, $xPos, $yPos, $this->blockSize, $this->blockSize);
     }
 }
コード例 #16
0
 /**
  * Applies the filter to the resource
  *
  * @param ImageResource $aResource
  */
 public function applyFilter(ImageResource $aResource)
 {
     //comic effect
     $width = $aResource->getX();
     $height = $aResource->getY();
     /* @var $imgK \imagemanipulation\ImageResource */
     $imgK = $aResource->cloneResource();
     $trueColorFilter = new ImageFilterTrueColor('ffffff', '000000');
     $trueColorFilter->applyFilter($imgK);
     imagecopymerge($aResource->getResource(), $imgK->getResource(), 0, 0, 0, 0, $width, $height, $this->opacity);
     imagedestroy($imgK->getResource());
 }
コード例 #17
0
 /**
  * Applies the filter to the resource
  *
  * @param ImageResource $aResource
  */
 public function applyFilter(ImageResource $aResource)
 {
     $this->width = $aResource->getX();
     $this->height = $aResource->getY();
     $im = $aResource->getResource();
     for ($x = 0; $x < $this->width; ++$x) {
         for ($y = 0; $y < $this->height; ++$y) {
             $index = imagecolorat($im, $x, $y);
             $rgb = imagecolorsforindex($im, $index);
             $this->vignetteToPixel($x, $y, $rgb);
             $color = imagecolorallocate($im, $rgb['red'], $rgb['green'], $rgb['blue']);
             imagesetpixel($im, $x, $y, $color);
         }
     }
 }
コード例 #18
0
 /**
  * (non-PHPdoc)
  * @see \imagemanipulation\filter\IImageFilter::applyFilter()
  */
 public function applyFilter(ImageResource $aResource)
 {
     if ($this->noise === 0) {
         return;
     }
     $resource = $aResource->getResource();
     $imagex = $aResource->getX();
     $imagey = $aResource->getY();
     for ($x = 0; $x < $imagex; ++$x) {
         for ($y = 0; $y < $imagey; ++$y) {
             if (rand(0, 1)) {
                 $rgb = imagecolorat($resource, $x, $y);
                 $red = $rgb >> 16 & 0xff;
                 $green = $rgb >> 8 & 0xff;
                 $blue = $rgb & 0xff;
                 $modifier = rand($this->noise * -1, $this->noise);
                 $red += $modifier;
                 $green += $modifier;
                 $blue += $modifier;
                 if ($red > 255) {
                     $red = 255;
                 }
                 if ($green > 255) {
                     $green = 255;
                 }
                 if ($blue > 255) {
                     $blue = 255;
                 }
                 if ($red < 0) {
                     $red = 0;
                 }
                 if ($green < 0) {
                     $green = 0;
                 }
                 if ($blue < 0) {
                     $blue = 0;
                 }
                 $newcol = imagecolorallocate($resource, $red, $green, $blue);
                 imagesetpixel($resource, $x, $y, $newcol);
             }
         }
     }
 }
コード例 #19
0
 /**
  * Applies the filter to the resource
  *
  * @param ImageResource $aResource
  */
 public function applyFilter(ImageResource $aResource)
 {
     if (!isset($this->opacity)) {
         return;
     }
     $this->opacity /= 100;
     //get image width and height
     $w = $aResource->getX();
     $h = $aResource->getY();
     //turn alpha blending off
     imagealphablending($aResource->getResource(), false);
     //find the most opaque pixel in the image (the one with the smallest alpha value)
     $minalpha = 127;
     for ($x = 0; $x < $w; $x++) {
         for ($y = 0; $y < $h; $y++) {
             $alpha = imagecolorat($aResource->getResource(), $x, $y) >> 24 & 0xff;
             if ($alpha < $minalpha) {
                 $minalpha = $alpha;
             }
         }
     }
     //loop through image pixels and modify alpha for each
     for ($x = 0; $x < $w; $x++) {
         for ($y = 0; $y < $h; $y++) {
             //get current alpha value (represents the TANSPARENCY!)
             $colorxy = imagecolorat($aResource->getResource(), $x, $y);
             $alpha = $colorxy >> 24 & 0xff;
             //calculate new alpha
             if ($minalpha !== 127) {
                 $alpha = 127 + 127 * $this->opacity * ($alpha - 127) / (127 - $minalpha);
             } else {
                 $alpha += 127 * $this->opacity;
             }
             //get the color index with new alpha
             $alphacolorxy = imagecolorallocatealpha($aResource->getResource(), $colorxy >> 16 & 0xff, $colorxy >> 8 & 0xff, $colorxy & 0xff, $alpha);
             //set pixel with the new color + opacity
             if (!imagesetpixel($aResource->getResource(), $x, $y, $alphacolorxy)) {
                 return;
             }
         }
     }
 }
コード例 #20
0
 /**
  * Applies the sepia filter to an image resource
  *
  * @param ImageResource $aResource
  */
 public function applyFilter(ImageResource $aResource)
 {
     $dstImg = $aResource->getResource();
     $imgX = $aResource->getX();
     $imgY = $aResource->getY();
     for ($y = 0; $y < $imgY; $y++) {
         for ($x = 0; $x < $imgX; $x++) {
             $dstRGB = imagecolorat($dstImg, $x, $y);
             //$dstA = ($dstRGB >> 24) << 1;
             $dstR = $dstRGB >> 16 & 0xff;
             $dstG = $dstRGB >> 8 & 0xff;
             $dstB = $dstRGB & 0xff;
             $newR = $dstR * 0.393 + $dstG * 0.769 + $dstB * 0.189 - $this->darken;
             $newG = $dstR * 0.349 + $dstG * 0.6860000000000001 + $dstB * 0.168 - $this->darken;
             $newB = $dstR * 0.272 + $dstG * 0.534 + $dstB * 0.131 - $this->darken;
             $newR = $newR > 255 ? 255 : ($newR < 0 ? 0 : $newR);
             $newG = $newG > 255 ? 255 : ($newG < 0 ? 0 : $newG);
             $newB = $newB > 255 ? 255 : ($newB < 0 ? 0 : $newB);
             $newRGB = imagecolorallocate($dstImg, $newR, $newG, $newB);
             imagesetpixel($dstImg, $x, $y, $newRGB);
         }
     }
 }
コード例 #21
0
 /**
  * Applies the sepia filter to an image resource
  *
  * @param ImageResource $aResource
  */
 public function applyFilter(ImageResource $aResource)
 {
     if ($this->red === 0 && $this->green === 0 && $this->blue === 0) {
         return;
     }
     $res = $aResource->getResource();
     $width = $aResource->getX();
     $height = $aResource->getY();
     for ($y = 0; $y < $height; $y++) {
         for ($x = 0; $x < $width; $x++) {
             $colorIndex = imagecolorat($res, $x, $y);
             $dstA = $colorIndex >> 24 << 1;
             $dstR = $colorIndex >> 16 & 0xff;
             $dstG = $colorIndex >> 8 & 0xff;
             $dstB = $colorIndex & 0xff;
             $newR = min(255, $this->red + $dstR);
             $newG = min(255, $this->green + $dstG);
             $newB = min(255, $this->blue + $dstB);
             $newColor = imagecolorallocatealpha($res, $newR, $newG, $newB, $dstA);
             imagesetpixel($res, $x, $y, $newColor);
         }
     }
 }
コード例 #22
0
 /**
  * Applies the filter to the resource
  *
  * @param ImageResource $aResource
  */
 public function applyFilter(ImageResource $aResource)
 {
     //comic effect
     $width = $aResource->getX();
     $height = $aResource->getY();
     $imgK = imagecreatetruecolor($width, $height);
     $lowR = $this->lowcolor->getRed();
     $lowG = $this->lowcolor->getGreen();
     $lowB = $this->lowcolor->getBlue();
     $highR = $this->highcolor->getRed();
     $highG = $this->highcolor->getGreen();
     $highB = $this->highcolor->getBlue();
     for ($y = 0; $y < $height; $y++) {
         for ($x = 0; $x < $width; $x++) {
             $rgb = imagecolorat($aResource->getResource(), $x, $y);
             $r = $rgb >> 16 & 0xff;
             $g = $rgb >> 8 & 0xff;
             $b = $rgb & 0xff;
             $bw = $r + $g + $b > 300 ? imagecolorallocate($imgK, $lowR, $lowG, $lowB) : imagecolorallocate($imgK, $highR, $highG, $highB);
             imagesetpixel($imgK, $x, $y, $bw);
         }
     }
     $aResource->setResource($imgK);
 }
コード例 #23
0
 /**
  * Tests ImageResource->getX()
  */
 public function testGetX()
 {
     $this->assertEquals($this->res->getX(), 600, 'Checking width');
 }
コード例 #24
0
 /**
  * Initializes the pixel strategy
  *
  * @param $aResource ImageImageResource
  */
 public function init(ImageResource $aResource)
 {
     if ($this->respectSmallerImage) {
         $x = $aResource->getX();
         $y = $aResource->getY();
         if ($x < $this->newWidth || $y < $this->newHeight) {
             if ($x < $y) {
                 $this->factor = (int) $x / $this->newWidth;
             } else {
                 $this->factor = (int) $y / $this->newHeight;
             }
         }
     }
 }
コード例 #25
0
 /**
  * @see IPixelStrategy::getSourceEnd()
  *
  * @param ImageResource $aResource
  * @return imagemanipulation\Coordinate
  */
 public function getSourceEnd(ImageResource $aResource)
 {
     return new Coordinate($aResource->getX(), $aResource->getY());
 }