Copy image from a website

S

_Stud

I'm trying to copy an image from a website, but can't seem to get it
right.

I know rio can copy a website in one line, but what about images?
Anyone have a good snippet using open-uri or something?
 
J

Jano Svitok

I'm trying to copy an image from a website, but can't seem to get it
right.

I know rio can copy a website in one line, but what about images?
Anyone have a good snippet using open-uri or something?

web page = (virtual) file
image = (virtual) file

just use open-uri + read and write the contents somewhere.

require 'open-uri'

File.open('logo.gif', 'wb') do |f|
f.write(open('http://www.google.com/intl/en_ALL/images/logo.gif').read)
end

J.
 
D

Dido Sevilla

T24gTm92IDIwLCAyMDA3IDI6MDAgQU0sIF9TdHVkIDxzdHVkbGVlMkBnbWFpbC5jb20+IHdyb3Rl
Ogo+IEknbSB0cnlpbmcgdG8gY29weSBhbiBpbWFnZSBmcm9tIGEgd2Vic2l0ZSwgYnV0IGNhbid0
IHNlZW0gdG8gZ2V0IGl0Cj4gcmlnaHQuCj4KPiBJIGtub3cgcmlvIGNhbiBjb3B5IGEgd2Vic2l0
ZSBpbiBvbmUgbGluZSwgYnV0IHdoYXQgYWJvdXQgaW1hZ2VzPwo+IEFueW9uZSBoYXZlIGEgZ29v
ZCBzbmlwcGV0IHVzaW5nIG9wZW4tdXJpIG9yIHNvbWV0aGluZz8KClVzaW5nIG1lY2hhbml6ZToK
CnJlcXVpcmUgJ21lY2hhbml6ZScKCmFnZW50ID0gV1dXOjpNZWNoYW5pemUubmV3CmltZyA9IGFn
ZW50LmdldCgiaHR0cDovL3d3dy5leGFtcGxlLmNvbS9pbWFnZS5qcGciKQppbWcuc2F2ZQoKd2ls
bCBsb2FkIHRoZSBKUEVHIGltYWdlIGltYWdlLmpwZyBmcm9tIHRoZSBzaXRlIHd3dy5leGFtcGxl
LmNvbSBhbmQKc2F2ZSBpdCBhcyBpbWFnZS5qcGcgb24gdGhlIGxvY2FsIGZpbGVzeXN0ZW0uCgot
LSAK5pmu6YCa44GY44KD44Gq44GE44Gu44GM5b2T54S244Gq44KJ562U44GI44KL56eB44Gv5L2V
44GM44Gn44GN44KL77yfCuaZrumAmuOBp+OCguaZrumAmuOBmOOCg+OBquOBj+OBpuaEn+OBmOOC
i+OBvuOBvuaEn+OBmOOCi+OBk+OBqOOBoOOBkeOCkuOBmeOCi+OCiO+8gQpodHRwOi8vc3Rvcm13
eXJtLmJsb2dzcG90LmNvbQo=
 

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
474,175
Messages
2,570,944
Members
47,492
Latest member
gabbywilliam

Latest Threads

Top