tags:

views:

42

answers:

1

how to read image file in ruby suppose i open a jpg file like this

path="c:/image/aj.jpg" File.open(path) do end

now how do i see this image file

+1  A: 

You can read arbitrary binary content

path = "/foo/bar/baz.jpg"
File.open(path, 'rb') {|file| file.read }

If you want to write this image to another..

File.open(path, 'rb') do |in|
  File.open("foo/bar/bob.jpg", 'wb') {|out| out.write(in.read) }
end

The binary flags are only required in Windows/DOS.

See the IO class

injekt
thanks injekt but how do i see this image file
Amit singh tomar
Define 'see', you'd need to open it up in your image viewing application. Assuming you're not talking about on a web page
injekt
yaa i want to open in paint
Amit singh tomar
You need to invoke `mspaint.exe` with the applicable command line flags. Do note though that I don't believe MSPaint handles JPG files. You'd need to search around google or perhaps submit another question regarding MSPaint and opening files via the command line.
injekt