mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
post processor
This commit is contained in:
parent
2226207ecd
commit
250bd3cd21
1 changed files with 17 additions and 4 deletions
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue