Beispiel #1
0
 public function WhiteBalance(&$gdimg, $targetColor = '')
 {
     if (phpthumb_functions::IsHexColor($targetColor)) {
         $targetPixel = array('red' => hexdec(substr($targetColor, 0, 2)), 'green' => hexdec(substr($targetColor, 2, 2)), 'blue' => hexdec(substr($targetColor, 4, 2)));
     } else {
         $Analysis = phpthumb_filters::HistogramAnalysis($gdimg, false);
         $targetPixel = array('red' => max(array_keys($Analysis['red'])), 'green' => max(array_keys($Analysis['green'])), 'blue' => max(array_keys($Analysis['blue'])));
     }
     $grayValue = phpthumb_functions::GrayscaleValue($targetPixel['red'], $targetPixel['green'], $targetPixel['blue']);
     $scaleR = $grayValue / $targetPixel['red'];
     $scaleG = $grayValue / $targetPixel['green'];
     $scaleB = $grayValue / $targetPixel['blue'];
     for ($x = 0; $x < ImageSX($gdimg); $x++) {
         for ($y = 0; $y < ImageSY($gdimg); $y++) {
             $currentPixel = phpthumb_functions::GetPixelColor($gdimg, $x, $y);
             $newColor = phpthumb_functions::ImageColorAllocateAlphaSafe($gdimg, max(0, min(255, round($currentPixel['red'] * $scaleR))), max(0, min(255, round($currentPixel['green'] * $scaleG))), max(0, min(255, round($currentPixel['blue'] * $scaleB))), $currentPixel['alpha']);
             ImageSetPixel($gdimg, $x, $y, $newColor);
         }
     }
     return true;
 }
 function HistogramOverlay(&$gdimg, $bands = '*', $colors = '', $width = 0.25, $height = 0.25, $alignment = 'BR', $opacity = 50, $margin = 5)
 {
     $Analysis = phpthumb_filters::HistogramAnalysis($gdimg);
     $histW = round($width > 1 ? min($width, ImageSX($gdimg)) : ImageSX($gdimg) * $width);
     $histH = round($width > 1 ? min($width, ImageSX($gdimg)) : ImageSX($gdimg) * $width);
     if ($gdHist = ImageCreateTrueColor($histW, $histH)) {
         $color_back = phpthumb_functions::ImageColorAllocateAlphaSafe($gdHist, 0, 0, 0, 127);
         ImageFilledRectangle($gdHist, 0, 0, $histW, $histH, $color_back);
         ImageAlphaBlending($gdHist, false);
         ImageSaveAlpha($gdHist, true);
         if ($gdHistTemp = ImageCreateTrueColor(256, 100)) {
             $color_back_temp = phpthumb_functions::ImageColorAllocateAlphaSafe($gdHistTemp, 255, 0, 255, 127);
             ImageAlphaBlending($gdHistTemp, false);
             ImageSaveAlpha($gdHistTemp, true);
             ImageFilledRectangle($gdHistTemp, 0, 0, ImageSX($gdHistTemp), ImageSY($gdHistTemp), $color_back_temp);
             $DefaultColors = array('r' => 'FF0000', 'g' => '00FF00', 'b' => '0000FF', 'a' => '999999', '*' => 'FFFFFF');
             $Colors = explode(';', $colors);
             $BandsToGraph = array_unique(preg_split('//', $bands));
             $keys = array('r' => 'red', 'g' => 'green', 'b' => 'blue', 'a' => 'alpha', '*' => 'gray');
             foreach ($BandsToGraph as $key => $band) {
                 if (!isset($keys[$band])) {
                     continue;
                 }
                 $PeakValue = max($Analysis[$keys[$band]]);
                 $thisColor = phpthumb_functions::ImageHexColorAllocate($gdHistTemp, phpthumb_functions::IsHexColor(@$Colors[$key]) ? $Colors[$key] : $DefaultColors[$band]);
                 $tempHeight = ImageSY($gdHistTemp);
                 for ($x = 0; $x <= 255; $x++) {
                     ImageLine($gdHistTemp, $x, $tempHeight - 1, $x, $tempHeight - 1 - round(@$Analysis[$keys[$band]][$x] / $PeakValue * $tempHeight), $thisColor);
                 }
                 ImageLine($gdHistTemp, 0, $tempHeight - 1, 255, $tempHeight - 1, $thisColor);
                 ImageLine($gdHistTemp, 0, $tempHeight - 2, 255, $tempHeight - 2, $thisColor);
             }
             ImageCopyResampled($gdHist, $gdHistTemp, 0, 0, 0, 0, ImageSX($gdHist), ImageSY($gdHist), ImageSX($gdHistTemp), ImageSY($gdHistTemp));
             ImageDestroy($gdHistTemp);
         } else {
             return false;
         }
         phpthumb_filters::WatermarkOverlay($gdimg, $gdHist, $alignment, $opacity, $margin);
         ImageDestroy($gdHist);
         return true;
     }
     return false;
 }