Hi, I need to download an image, and I''ve mucked about with Net::HTTP resp = Net::HTTP.get_response(''www.mydomain.com'', ''/test.jpg'') f = File.new("test.jpg","w") f.write(response.body) And various other combinations using HTTP.get etc. Anyway, I get an image, but it looks very psychedelic. This is obviously not the correct way. I also don''t want to use Imagemagick for this. Has anybody done this before? Joerg -- Posted via http://www.ruby-forum.com/.
On 1/22/06, Joerg Diekmann <joergd@pobox.com> wrote:> Hi, > > I need to download an image, and I''ve mucked about with Net::HTTP > > resp = Net::HTTP.get_response(''www.mydomain.com'', ''/test.jpg'') > f = File.new("test.jpg","w") > f.write(response.body) > > And various other combinations using HTTP.get etc. Anyway, I get an > image, but it looks very psychedelic. This is obviously not the correct > way. I also don''t want to use Imagemagick for this. > > Has anybody done this before?Are you on Windows? If so, you need to use: f = File.new("test.jpg","wb") See http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/18810 for a discussion of why, and http://www.ruby-doc.org/core/classes/IO.html for the documentation of this mode.> JoergAnthony
On Jan 22, 2006, at 8:06 AM, Anthony Elizondo wrote:> On 1/22/06, Joerg Diekmann <joergd@pobox.com> wrote: >> Hi, >> >> I need to download an image, and I''ve mucked about with Net::HTTP >> >> resp = Net::HTTP.get_response(''www.mydomain.com'', ''/test.jpg'') >> f = File.new("test.jpg","w") >> f.write(response.body) >> >> And various other combinations using HTTP.get etc. Anyway, I get an >> image, but it looks very psychedelic. This is obviously not the >> correct >> way. I also don''t want to use Imagemagick for this. >> >> Has anybody done this before? > > Are you on Windows? If so, you need to use: > > f = File.new("test.jpg","wb") > > See http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/18810 > for a discussion of why, and > http://www.ruby-doc.org/core/classes/IO.html for the documentation of > this mode. > >> Joerg > > AnthonyAlso you are trying to write response.body into the file when you should be using resp.body because resp is the var you used to set up the Net::HTTP object Cheers- -Ezra Zygmuntowicz WebMaster Yakima Herald-Republic Newspaper ezra@yakima-herald.com 509-577-7732