【问题标题】:Editing image colors in PHP - color exchange在 PHP 中编辑图像颜色 - 颜色交换
【发布时间】:2015-09-12 20:03:12
【问题描述】:
【问题讨论】:
标签:
php
image
imagemagick
gd
【解决方案2】:
我不是 PHP 程序员,但它看起来像这样:
#!/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");
?>
哪个转换了这个
到这里