"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