how to read image file in ruby
how to read image file in ruby suppose i open a jpg file like thi开发者_JAVA百科s
path="c:/image/aj.jpg" File.open(path) do end
now how do i see this image file
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
this is how to open mspaint in ruby
irb>print("mspaint #{%x{path=c:/image/aj.jpg}}")#
irb>print("mspaint #{%x{mspaint a.jpg}}")# this is open your jpg file with mspaint
OR
irb>print("mspaint #{%x{mspaint c:/image/a.jpg}}")#
精彩评论