Page 1 of 1

rmagick Pixel.from_color

Posted: 2013-10-19T08:09:23-07:00
by tamflu
i am trying to replace pixel of certain color with black ones but i am unable to select colors other than black(#000000) or white(#FFFFFF).

Code: Select all

convert image-input.png -unique-colors -depth 8 txt:- > color.txt
this shows that there are other pixel colors present beside black and white.

Code: Select all

image = ImageList.new("image-input.png")
image.quantize(number_colors=256, colorspace=RGBColorspace, dither=RiemersmaDitherMethod, tree_depth=0, measure_error=false)
image2 = Image.new(240,240)

color = Pixel.from_color('#E1E1E1')

(0..image.columns).each do |x|
    (0..image.rows).each do |y|
        pixel = image.pixel_color(x, y)
        if pixel.fcmp(color)
            image2.pixel_color(x, y, "#000000")
        end
    end
end