Пример #1
0
 public function Threshold(&$gdimg, $cutoff)
 {
     $width = ImageSX($gdimg);
     $height = ImageSY($gdimg);
     $cutoff = min(255, max(0, $cutoff ? $cutoff : 128));
     for ($x = 0; $x < $width; $x++) {
         for ($y = 0; $y < $height; $y++) {
             $currentPixel = phpthumb_functions::GetPixelColor($gdimg, $x, $y);
             $grayPixel = phpthumb_functions::GrayscalePixel($currentPixel);
             if ($grayPixel['red'] < $cutoff) {
                 $newColor = phpthumb_functions::ImageColorAllocateAlphaSafe($gdimg, 0x0, 0x0, 0x0, $currentPixel['alpha']);
             } else {
                 $newColor = phpthumb_functions::ImageColorAllocateAlphaSafe($gdimg, 0xff, 0xff, 0xff, $currentPixel['alpha']);
             }
             ImageSetPixel($gdimg, $x, $y, $newColor);
         }
     }
     return true;
 }