Reading files from the internet into RMagick

S

Szymon Rozga

I am not sure how to go about doing this. I would like to get a file
given an URL. The I would like to mess around with that file, but I am
having a hard time actually initializing the Magick::Image object.

I read the image using open-uri like so:
require 'rmagick'
require 'open-uri'
include Magick

open(url) do |f|
image = from_blob(f.read)
end


However, it turns out that f is of type "Tempfile" and calling read
returns "" and read(int) returns nil. So I don't know where to go from
here. How can this be done?

Thanks,
-Szymon
 
W

Wilson Bilkovich

I am not sure how to go about doing this. I would like to get a file
given an URL. The I would like to mess around with that file, but I am
having a hard time actually initializing the Magick::Image object.

I read the image using open-uri like so:
require 'rmagick'
require 'open-uri'
include Magick

open(url) do |f|
image = from_blob(f.read)
end


However, it turns out that f is of type "Tempfile" and calling read
returns "" and read(int) returns nil. So I don't know where to go from
here. How can this be done?

Does this work?
open(url, 'rb') do |f|
image = from_blob(f.read)
end
 
S

Szymon Rozga

That works. I wasn't aware of the way binary IO was done in Ruby.
Thanks!

-Szymon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top