Skip to content

Instantly share code, notes, and snippets.

@AlexJWayne
Created August 12, 2009 23:52
Show Gist options
  • Select an option

  • Save AlexJWayne/166862 to your computer and use it in GitHub Desktop.

Select an option

Save AlexJWayne/166862 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'open-uri'
require 'hpricot'
def find_biggest_image_url(url)
page = Hpricot(open(url))
biggest_image_url = nil;
biggest_image_area = 0;
page.search('img') do |img|
width = img.attributes['width'].to_i
height = img.attributes['height'].to_i
area = width * height
if area > biggest_image_area
biggest_image_area = area
biggest_image_url = URI.parse(url).merge(img.attributes['src'])
end
end
biggest_image_url
end
puts find_biggest_image_url('http://www.touchmyapps.com/2009/04/03/the-void-in-review-the-space-between/')
puts find_biggest_image_url('http://en.wikipedia.org/wiki/U2')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment