save images from the web ?

  • Thread starter Boris \BXS\ Schulz
  • Start date
B

Boris \BXS\ Schulz

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
 
D

daz

Boris "BXS" Schulz said:
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
 

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

Forum statistics

Threads
473,888
Messages
2,569,964
Members
46,292
Latest member
IngeborgLa

Latest Threads

Top