开发者

how to read image file in ruby

开发者 https://www.devze.com 2023-01-09 09:02 出处:网络
how to read image file in ruby suppose i open a jpg file like thi开发者_JAVA百科s path=\"c:/image/aj.jpg\"

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}}")# 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号