rmagick Pixel.from_color

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
tamflu
Posts: 1
Joined: 2013-10-19T07:38:31-07:00
Authentication code: 6789

rmagick Pixel.from_color

Post 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
Post Reply