0

so let me preface this with the fact that I am a beginner at ruby and FXruby. I would like to know how I can fetch images by using a URL. This is the code I used when getting them off my desktop:

require 'rubygems'

require 'fox16'

include Fox


class Image_Viewer <FXMainWindow
  def initialize(app)
    super(app, "Image Viewer", :opts => DECOR_ALL, :width => 500, :height => 450) 
    @pic = File.open("/Users/AdamAshwal/Desktop/image.jpg", "rb")
    @pic2 = FXJPGImage.new(app, @pic.read)
    FXImageFrame.new(self, @pic2)

end 
  def create
    super
    self.show(PLACEMENT_SCREEN)
end

end


app = FXApp.new
mainwin = Image_Viewer.new(app)

app.create
app.run
Adam Ashwal
  • 1,472
  • 1
  • 19
  • 36

2 Answers2

0

Just do a:

require 'open-url'

then

@pic = open("http://website.com/imgs/image.png")    

Then treat it as you would treat any other File

Reese Moore
  • 11,524
  • 3
  • 24
  • 32
0

That should be

require 'open-uri'

and not

require 'open-url'
  • Ya, cool thanks. Then can I just copy and paste in any url? Like: @pic = File.open("http://www.dream-worlds.net/forum/uploads/100/platypus.jpg", "rb") – Adam Ashwal Nov 03 '10 at 22:16
  • For one thing, you need to use open() instead of File.open(), as Resse Moore showed in his example. For another thing, the string you listed ("dream-worlds.net...") is not a URL. For yet another thing, even if I make it a URL I can't fetch that image over the 'net anyways (permission denied). – Lyle Johnson Nov 11 '10 at 16:10