FIX stretched thumbnails

This commit is contained in:
Régis Hanol
2013-11-25 18:36:13 +01:00
parent 549060867d
commit 6b6c3d05dd
3 changed files with 28 additions and 6 deletions

View File

@ -70,11 +70,22 @@ class CookedPostProcessor
end
def limit_size!(img)
w, h = get_size_from_image_sizes(img["src"], @opts[:image_sizes]) || get_size(img["src"])
# retrieve the size from
# 1) the width/height attributes
# 2) the dimension from the preview (image_sizes)
# 3) the dimension of the original image (HTTP request)
w, h = get_size_from_attributes(img) ||
get_size_from_image_sizes(img["src"], @opts[:image_sizes]) ||
get_size(img["src"])
# limit the size of the thumbnail
img["width"], img["height"] = ImageSizer.resize(w, h)
end
def get_size_from_attributes(img)
w, h = img["width"].to_i, img["height"].to_i
return [w, h] if w > 0 && h > 0
end
def get_size_from_image_sizes(src, image_sizes)
return unless image_sizes.present?
image_sizes.each do |image_size|