# Copy image from a website

**URL:** <https://www.ruby-forum.com/t/copy-image-from-a-website/120681>\
**Category:** Ruby\
**Created:** [November 19, 2007, 7:00pm UTC](https://www.ruby-forum.com/t/copy-image-from-a-website/120681 "2007-11-19T19:00:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![studlee2](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/278dde/32.png) [@studlee2](https://www.ruby-forum.com/u/studlee2)\
**Post date:** [November 19, 2007, 7:00pm UTC](https://www.ruby-forum.com/t/copy-image-from-a-website/120681/1 "2007-11-19T19:00:44Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![studlee2](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/278dde/32.png) [@studlee2](https://www.ruby-forum.com/u/studlee2)\
**Post date:** [November 19, 2007, 10:21pm UTC](https://www.ruby-forum.com/t/copy-image-from-a-website/120681/2 "2007-11-19T22:21:23Z")

</div>

On Nov 19, 2007 7:00 PM, \_Stud [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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](http://www.google.com/intl/en_ALL/images/logo.gif)’).read)  
end

J.

---

<div class="post-metadata">

**Author:** ![studlee2](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/278dde/32.png) [@studlee2](https://www.ruby-forum.com/u/studlee2)\
**Post date:** [November 21, 2007, 8:35am UTC](https://www.ruby-forum.com/t/copy-image-from-a-website/120681/3 "2007-11-21T08:35:27Z")

</div>

On Nov 20, 2007 2:00 AM, \_Stud [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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?

Using mechanize:

require ‘mechanize’

agent = WWW::Mechanize.new  
img = agent.get(“[http://www.example.com/image.jpg](http://www.example.com/image.jpg)”)  
img.save

will load the JPEG image image.jpg from the site [www.example.com](http://www.example.com) and  
save it as image.jpg on the local filesystem.

---

<div class="post-metadata">

**Author:** ![studlee2](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/278dde/32.png) [@studlee2](https://www.ruby-forum.com/u/studlee2)\
**Post date:** [April 20, 2009, 11:51am UTC](https://www.ruby-forum.com/t/copy-image-from-a-website/120681/4 "2009-04-20T11:51:49Z")

</div>

Hi All,

Get all images from given URL

Desktop Application from jazzez

Kindly go through below link and download the EXE file.

> **[jazzez-image-v2.exe | Powered by Box](https://app.box.com/s/m5vxqpr3r1)**
>
> Get all images from the given URL

Install in Windows machine and enjoy with impressed images

Regards,  
P.Raveendran

> **[Raveendran](https://raveendran.wordpress.com/)**
>
> Nothing is impossible...
