Turn the color black if its r + b> 150

I looked at SO, but I could not find a single similar question.

After opening the image in PHP, I want to check every pixel, and if their red + green values ​​are below 150, I would turn that pixel to white, instead, if the sum is above 150, I would turn it from a pixel to black.

Is it possible?

I tried with imagefilter() , but I can't get it to work properly. Perhaps there are more suitable features.

+4
source share
2 answers

sort of

 $image = imagecreatefrompng($img); $xdim = imagesx($image); $ydim = imagesy($image); for ($x = 1; $x <= $xdim-1; $x++) { for ($y = 1; $y <= $ydim-1; $y++) { $rgb = imagecolorat($image, $x, $y); if($rgb>150) $color = 0x00; else $color = 0xFF; } } 
+3
source

Look at using the imagecolorat function (I think it might be part of the GD library). You can get RGB from this. Then use imagecolorset to set the new RGB.

+3
source

Source: https://habr.com/ru/post/1398253/


All Articles