Instantly share code, notes, and snippets.

Embed
What would you like to do?
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