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

前端 未结 3 1787
南方客
南方客 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:28

    If you know what image format that is being used, you could likely use that information to avoid accessing through pixel values (possibly destroying image quality), otherwise do something similar to this:

    1. Get hold of the image as an array of pixels
    2. Map over each pixel, setting it to the background color if it lies within a certain threshold step away from any of the colors you want to remove.

    This relies on that there is a given background color at any time that the pixels can be set to and that you can identify the colors to remove.

提交回复
热议问题