imagemagick - Read an image pixel by pixel in Ruby -
i'm trying open image file , store list of pixels color in variable/array can output them 1 one.
image type: bmp, jpg, gif or png. of them fine , 1 needs supported. color output: rgb or hex.
i've looked @ couple libraries (rmagick, quick_magick, mini_magick, etc) , seem overkill. heroku has sort of difficulties imagemagick , tests don't run. application in sinatra.
any suggestions?
you can use rmagick's each_pixel method this. each_pixel receives block. each pixel, block passed pixel, column number , row number of pixel. iterates on pixels left-to-right , top-to-bottom.
so like:
pixels = [] img.each_pixel |pixel, c, r| pixels.push(pixel) end # pixels contains each individual pixel of img
Comments
Post a Comment