Beispiel #1
0
 public function SourceTransparentColorMask(&$gdimg, $hexcolor, $min_limit = 5, $max_limit = 10)
 {
     $width = ImageSX($gdimg);
     $height = ImageSY($gdimg);
     if ($gdimg_mask = ImageCreateTrueColor($width, $height)) {
         $R = hexdec(substr($hexcolor, 0, 2));
         $G = hexdec(substr($hexcolor, 2, 2));
         $B = hexdec(substr($hexcolor, 4, 2));
         $targetPixel = array('red' => $R, 'green' => $G, 'blue' => $B);
         $cutoffRange = $max_limit - $min_limit;
         for ($x = 0; $x < $width; $x++) {
             for ($y = 0; $y < $height; $y++) {
                 $currentPixel = phpthumb_functions::GetPixelColor($gdimg, $x, $y);
                 $colorDiff = phpthumb_functions::PixelColorDifferencePercent($currentPixel, $targetPixel);
                 $grayLevel = min($cutoffRange, MAX(0, -$min_limit + $colorDiff)) * (255 / MAX(1, $cutoffRange));
                 $newColor = ImageColorAllocate($gdimg_mask, $grayLevel, $grayLevel, $grayLevel);
                 ImageSetPixel($gdimg_mask, $x, $y, $newColor);
             }
         }
         return $gdimg_mask;
     }
     return false;
 }