Skip to content

Instantly share code, notes, and snippets.

@varnie
varnie / Ruby images downloader
Created August 4, 2011 16:09
Three ways of handling images from the net using Ruby
#!/usr/bin/env ruby
require 'open-uri'
require 'pool' #taken fron http://burgestrand.se/code/ruby-thread-pool/
IMG_REGEXP = /\<img[^(src)]*src=(\"|\')((http:\/\/)?[\w\.\/:-]+)\1[^\\>]*\\?\>/
VALID_IMAGE_EXTENSION_REGEXP = /.*\.(gif|tif|png|jpeg|jpg)$/
def image_extension_correct?(image)
not image.nil? and image =~ VALID_IMAGE_EXTENSION_REGEXP
end