Skip to content

Instantly share code, notes, and snippets.

@seancdavis
Created December 7, 2015 12:24
Show Gist options
  • Save seancdavis/0438bfdfe799d60a1365 to your computer and use it in GitHub Desktop.
Save seancdavis/0438bfdfe799d60a1365 to your computer and use it in GitHub Desktop.
Download a collection of images from URLs using Ruby
require 'open-uri'
def download_image(url, dest)
open(url) do |u|
File.open(dest, 'wb') { |f| f.write(u.read) }
end
end
urls = [
'http://petsfans.com/wp-content/uploads/2014/11/edfsaf.jpg',
'http://dailynewsdig.com/wp-content/uploads/2012/06/funny-cats.jpg',
'https://i.ytimg.com/vi/tntOCGkgt98/maxresdefault.jpg'
]
urls.each { |url| download_image(url, url.split('/').last) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment