How to remove all colours that not X color?
Posted: 2010-07-19T08:28:41-07:00
Hi,
I need to remove colours or an image. For example, I need to remove all non BLUE colours. How can I achieve this?
I have this code to go pixel by pixel on the selected image:
Any ideas on how to achieve this?
Best regards,
I need to remove colours or an image. For example, I need to remove all non BLUE colours. How can I achieve this?
I have this code to go pixel by pixel on the selected image:
Code: Select all
<?php
$img = imagecreatefromjpeg("img.jpg");
$w = imagesx($img);
$h = imagesy($img);
for($y=0;$y<$h;$y++) {
for($x=0;$x<$w;$x++) {
$rgb = imagecolorat($img, $x, $y);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
echo "#".str_repeat("0",2-strlen(dechex($r))).dechex($r).
str_repeat("0",2-strlen(dechex($g))).dechex($g).
str_repeat("0",2-strlen(dechex($b))).dechex($b).",";
}
echo "<br />\r\n";
}
?>
Any ideas on how to achieve this?
Best regards,