refined Posted January 4, 2008 Share Posted January 4, 2008 I have an image, greyscale. I want to convert everything that is *NOT* white to black. How can I do this? Is there such a function that exists to convert a greyscale image to 100% black or 100% white ? Link to comment https://forums.phpfreaks.com/topic/84556-php-image-using-gd-in-php-help/ Share on other sites More sharing options...
Barand Posted January 5, 2008 Share Posted January 5, 2008 try <?php $im = imagecreatefromjpeg('gmc.jpg'); $white = imagecolorclosest($im, 255,255,255); $black = imagecolorallocate($im, 0,0,0); $sx = imagesx($im); $sy = imagesy($im); for ($x=0; $x<$sx; $x++) { for ($y=0; $y<$sy; $y++) { $c = imagecolorat($im, $x, $y); if ($c != $white) { imagesetpixel($im, $x, $y, $black); } } } header("content-type:image/jpeg"); imagejpeg($im); imagedestroy($im); ?> Link to comment https://forums.phpfreaks.com/topic/84556-php-image-using-gd-in-php-help/#findComment-431427 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.