|
|
|
| Подскажите плиз, можно ли средствами PHP 4 изменить яркость, контрастность изображения, а так же перевести его в черно-белое?
В 5-ке есть imagefilter, а 4-ка не удел? | |
|
|
|
|
|
|
|
для: sd607
(24.04.2007 в 01:37)
| | Чёрно-белое (градации серого):
<?php
$im = imagecreatefromjpeg("036.jpg");
for ( $i = 0; $i < imagesx($im); $i++ ) {
for ( $j = 0; $j < imagesy($im); $j++ ) {
$index = imagecolorat($im, $i, $j);
$col = imagecolorsforindex($im, $index);
$gray = ($col['red'] + $col['green'] + $col['blue']) / 3;
$color = imagecolorallocate($im, $gray, $gray, $gray);
imagesetpixel($im, $i, $j, $color);
}
}
header("Content-Type: image/jpeg");
imagejpeg($im, null, 100);
|
Яркость:
<?php
$l = 100; // уровень яркости
$im = imagecreatefromjpeg("039.jpg");
for ( $i = 0; $i < imagesx($im); $i++ ) {
for ( $j = 0; $j < imagesy($im); $j++ ) {
$index = imagecolorat($im, $i, $j);
$col = imagecolorsforindex($im, $index);
$r = $col['red'] + $l;
$g = $col['green'] + $l;
$b = $col['blue'] + $l;
if ( $r > 255 ) $r = 255; elseif ( $r < 0 ) $r = 0;
if ( $g > 255 ) $g = 255; elseif ( $g < 0 ) $g = 0;
if ( $b > 255 ) $b = 255; elseif ( $b < 0 ) $b = 0;
$color = imagecolorallocate($im, $r, $g, $b);
imagesetpixel($im, $i, $j, $color);
}
}
header("Content-Type: image/jpeg");
imagejpeg($im, null, 100);
|
Контрастность:
<?php
$l = 0.6; // уровень контрастности
$im = imagecreatefromjpeg("trigun.jpg");
for ( $i = 0; $i < imagesx($im); $i++ ) {
for ( $j = 0; $j < imagesy($im); $j++ ) {
$index = imagecolorat($im, $i, $j);
$col = imagecolorsforindex($im, $index);
$r = $col['red'] * $l;
$g = $col['green'] * $l;
$b = $col['blue'] * $l;
if ( $r > 255 ) $r = 255;
if ( $g > 255 ) $g = 255;
if ( $b > 255 ) $b = 255;
$color = imagecolorallocate($im, $r, $g, $b);
imagesetpixel($im, $i, $j, $color);
}
}
header("Content-Type: image/jpeg");
imagejpeg($im, null, 100);
|
Про контрастность сомневаюсь. | |
|
|
|
|
|
|
|
для: Саня
(25.04.2007 в 08:18)
| | С яркостью и градациями серого тоже прокол.
Дело в том, что яркость цветовых составляющих по разному воспринимаются глазом. Обычно применяются коэффициенты 29.9% для красного, 58.7% для зеленого и 11.4% для голубого цветов. | |
|
|
|