How to to remove certain colors from an image with PHP or Ruby?

前端 未结 3 1785
南方客
南方客 2021-01-01 07:56

Say there are 3 circles: red, blue, black.

I only want the black circle to remain. How can I remove the red and blue circles?

3条回答
  •  既然无缘
    2021-01-01 08:27

    ImageMagick will do it. Just shell out to this command:

    convert circles.png -channel black -white-threshold 10% circles2.png
    

    You didn't say what to do with green. This script takes the easy way out and wipes out green as well. Actually, it wipes out anything not black.

    The RMagick libary lets you drive imagemagick with Ruby. Sadly, it's not working in my distro, so I can't prepare an example for you. However, using system or backtick to shell out to the command works just fine.

提交回复
热议问题