diff --git a/Gemfile b/Gemfile index f5d1a49..1c941ae 100644 --- a/Gemfile +++ b/Gemfile @@ -31,6 +31,7 @@ gem 'nokogiri' gem 'fastimage' gem 'open_uri_redirections' gem 'mechanize' +gem 'image_info' gem 'text' diff --git a/Gemfile.lock b/Gemfile.lock index 7d3263a..6b62390 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -71,6 +71,8 @@ GEM domain_name (0.5.24) unf (>= 0.0.5, < 1.0.0) erubis (2.7.0) + ethon (0.7.4) + ffi (>= 1.3.0) execjs (2.5.2) factory_girl (4.5.0) activesupport (>= 3.0.0) @@ -88,11 +90,16 @@ GEM faraday_middleware (~> 0.9) loofah (~> 2.0) sax-machine (~> 1.0) + ffi (1.9.10) globalid (0.3.5) activesupport (>= 4.1.0) http-cookie (1.0.2) domain_name (~> 0.5) i18n (0.7.0) + image_info (1.0.0) + image_size + typhoeus + image_size (1.4.1) jbuilder (2.3.1) activesupport (>= 3.0.0, < 5) multi_json (~> 1.2) @@ -210,6 +217,8 @@ GEM tins (1.5.4) turbolinks (2.5.3) coffee-rails + typhoeus (0.7.2) + ethon (>= 0.7.4) tzinfo (1.2.2) thread_safe (~> 0.1) uglifier (2.7.1) @@ -239,6 +248,7 @@ DEPENDENCIES factory_girl_rails fastimage feedjira + image_info jbuilder (~> 2.0) jquery-rails mechanize diff --git a/app/models/subscription.rb b/app/models/subscription.rb index a9955e3..f504bc6 100644 --- a/app/models/subscription.rb +++ b/app/models/subscription.rb @@ -40,10 +40,20 @@ def get_feature_imgs(articles) # => Takes 13s for 20 articles from "http://rss.n agent = Mechanize.new page = agent.get(article_url).images.each do |img| - all_img_urls << img.src - dimensions = FastImage.size(img.src) - dimensions ? area = dimensions.reduce(1) { |length, width| length * width } : area = 0 - img_areas << area + p ">" * 25 + p img + p ">" * 25 + img_src = img.src + if img_src + all_img_urls << img_src + img = ImageInfo.from(img_src)[0] + img ? area = img.size.reduce(1) { |length, width| length * width } : area = 0 + img_areas << area + else + all_img_urls << "NONE" + img_areas << 0 + end + end largest = img_areas.index(img_areas.max)