From: Rob Biedenharn Date: 2009-12-08T03:35:26+09:00 Subject: Re: Reading Images On Dec 7, 2009, at 1:03 PM, Fleck Jean-Julien wrote: > Hello, > >> The problem is not with ruby, but with the complexity of the .jpeg >> format. >> RMagick has done all the hard work, but it depends on installing >> ImageMagick. I use RMagick regularly, and installing ImageMagick >> took a >> couple of false starts (I use both OSX and Ubuntu), but in the end >> I got all >> the dependencies right. Then, RMagick "just works." So, install >> ImageMagick >> and RMagick and impress your mates. > > > Well, rather than using RMagick which seem a bit complex at first > sight, you can always call 'convert' (from ImageMagick) with a system > call and transform your jpg in a text file: > > jpg = "image.jpg" > txt = "image.txt" > system "convert #{jpg} #{txt}" > > The image.txt file looks like > > # ImageMagick pixel enumeration: 712,490,255,RGB > 0,0: (226,188,115) #E2BC73 rgb(226,188,115) > 1,0: (227,189,116) #E3BD74 rgb(227,189,116) > 2,0: (226,188,115) #E2BC73 rgb(226,188,115) > ... > 709,489: (224,207,125) #E0CF7D rgb(224,207,125) > 710,489: (211,203,120) #D3CB78 rgb(211,203,120) > 711,489: (134,129, 45) #86812D rgb(134,129,45) > > and its really easy to get the size (712x490) and the pixels colors > reading the file directly throught > > File.open(txt) do |f| > f.readlines.each do |line| > # action on each line using regexp to get the colors > end > end > > Cheers, > > -- > JJ Fleck > PCSI1 Lycée Kléber Oh, new to me! I'm going to have to remember that one. I have to admit that I use Ruby system() calls to run various 'convert' operations rather than go the RMagick route, too. Needing all the pixel data might make it worth using RMagick, but you certainly can't get much simpler that your image-as-text solution. -Rob Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com