I'm trying to read the value of each pixel as hex (HTML notation) using RMagick
or Chunky_PNG
e.g. #5DBCD2
. At the moment I have the below which kind of does what I want but I couldn't find the right way to actually read the hex value. I'd prefer to use Chunky_PNG
though, thanks!
require 'chunky_png'
img = ChunkyPNG::Image.from_file("image.png")
height = img.dimension.height
width = img.dimension.width
height.times do |i|
width.times do |j|
p [ChunkyPNG::Color.r(img[j,i]), ChunkyPNG::Color.g(img[j,i]), ChunkyPNG::Color.b(img[j,i])]
end
end
OR
require 'RMagick'
include Magick
image = ImageList.new("image.png")
(0..image.columns).each do |x|
(0..image.rows).each do |y|
pixel = image.pixel_color(x, y)
p [pixel.red, pixel.green, pixel.blue]
end
end