为了具体描述我的问题,我试图将接近黑色的所有颜色(在阈值内)转换为完全黑色。例如,在RGB术语中,所有分量小于50的颜色变为(0,0,0)。我知道这可以通过下面的链接在GIMP中完成,但是有人知道这可以用PHP完成吗?
答案 0 :(得分:0)
答案 1 :(得分:0)
I'm no PHP programmer, but it would look something like this:
#!/usr/local/bin/php -f
<?php
$im = imagecreatefrompng("image.png");
$black = imagecolorallocate($im,0,0,0);
$w = imagesx($im); // image width
$h = imagesy($im); // image height
for($x = 0; $x < $w; $x++) {
for($y = 0; $y < $h; $y++) {
// Get the colour of this pixel
$rgb = imagecolorat($im, $x, $y);
$r = ($rgb >> 16) & 0xFF;
if($r>=50)continue; // Don't bother calculating rest if over threshold
$g = ($rgb >> 8) & 0xFF;
if($g>=50)continue; // Don't bother calculating rest if over threshold
$b = $rgb & 0xFF;
if($b>=50)continue; // Don't bother calculating rest if over threshold
// Change this pixel to black
imagesetpixel($im,$x,$y,$black);
}
}
imagepng($im,"result.png");
?>
Which converts this
to this