[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Reading files from the internet into RMagick

szymon.rozga

9/22/2006 2:59:00 AM

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

2 Answers

Wilson Bilkovich

9/22/2006 3:26:00 AM

0

On 9/21/06, Szymon Rozga <szymon.rozga@gmail.com> wrote:
> 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

szymon.rozga

9/22/2006 1:36:00 PM

0

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

-Szymon

Wilson Bilkovich wrote:
> On 9/21/06, Szymon Rozga <szymon.rozga@gmail.com> wrote:
> > 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