post processor

This commit is contained in:
Sam Saffron 2013-02-21 12:07:36 +11:00
parent 2226207ecd
commit 250bd3cd21

View file

@ -4,7 +4,7 @@
require_dependency 'oneboxer' require_dependency 'oneboxer'
class CookedPostProcessor class CookedPostProcessor
require 'open-uri'
def initialize(post, opts={}) def initialize(post, opts={})
@dirty = false @dirty = false
@ -73,6 +73,11 @@ class CookedPostProcessor
end end
def optimize_image(src) def optimize_image(src)
# uri = get_image_uri(src)
# uri.open(read_timeout: 20) do |f|
#
# end
src src
end end
@ -127,11 +132,19 @@ class CookedPostProcessor
@size_cache[url] ||= FastImage.size(url) @size_cache[url] ||= FastImage.size(url)
end end
def get_image_uri(url)
uri = URI.parse(url)
if %w(http https).include?(uri.scheme)
uri
else
nil
end
end
# Retrieve the image dimensions for a url # Retrieve the image dimensions for a url
def image_dimensions(url) def image_dimensions(url)
uri = URI.parse(url) uri = get_image_uri(url)
return nil unless uri
return nil unless %w(http https).include?(uri.scheme)
w, h = get_size(url) w, h = get_size(url)
ImageSizer.resize(w, h) if w && h ImageSizer.resize(w, h) if w && h
end end