How do you convert an image to black and white in PHP

后端 未结 7 1594
长情又很酷
长情又很酷 2020-12-01 14:34

How does one go about converting an image to black and white in PHP?

Not just turning it into greyscale but every pixel made black or white?

7条回答
  •  被撕碎了的回忆
    2020-12-01 15:08

    $rgb = imagecolorat($original, $x, $y);
            $r = ($rgb >> 16) & 0xFF;
            $g = ($rgb >> 8 ) & 0xFF;
            $b = $rgb & 0xFF;
    
            $gray = $r + $g + $b/3;
            if ($gray >0xFF) {$grey = 0xFFFFFF;}
            else { $grey=0x000000;}
    

提交回复
热议问题