[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

save images from the web ?

Boris \"BXS\" Schulz

11/8/2003 12:22:00 AM

Hi,

I would like to save an image from a website, using a ruby script. It
all seemes to work, as the file has the right size and the colors seem
to be OK, but the image itself is nothing but garbage. So it would seem
I used the wrong method to put the image data into my file.
Any help would be appreciated.

greetings, BXS


This is the code that I use:
---
h = Net::HTTP.new('www.sinfest.net', 80, 'myproxy :-) ', 3128)
resp, data = h.get('/comics/sf20031107.gif', nil)
if resp.message == "OK"
f = File.open("sinfest.gif", "w+")
f << data # I guess this is the problem
f.close()
end

2 Answers

daz

11/8/2003 1:57:00 AM

0


"Boris "BXS" Schulz" <bxs@hadiko.de> wrote:
> Hi,
>
> I would like to save an image from a website, using a ruby script. It
> all seemes to work, as the file has the right size and the colors seem
> to be OK, but the image itself is nothing but garbage. So it would seem
> I used the wrong method to put the image data into my file.
> Any help would be appreciated.
>
> greetings, BXS
>
>
> This is the code that I use:
> ---
> h = Net::HTTP.new('www.sinfest.net', 80, 'myproxy :-) ', 3128)
> resp, data = h.get('/comics/sf20031107.gif', nil)
> if resp.message == "OK"
> f = File.open("sinfest.gif", "w+")

f = File.open("sinfest.gif", "wb+") # <======###

> f << data # I guess this is the problem # (no)
> f.close()
> end
>

Your on NT, so you need to save as binary.
Here's what I used (no proxy):

require 'net/http'
h = Net::HTTP.new('www.sinfest.net', 80)
resp, data = h.get('/comics/sf20031107.gif', nil)
if resp.message == "OK"
File.open("sinfest.gif", "wb+") do |f|
f << data
end
end


greetings returned,

daz



Boris \"BXS\" Schulz

11/8/2003 3:05:00 PM

0

Hi,

and thanks, that worked.

greetings, BXS