FIX: rescale image during cooked_post_processor when only img height or width is specified

This commit is contained in:
kerryliu
2015-08-29 14:56:25 -07:00
parent aa45429989
commit c85835afc3
2 changed files with 45 additions and 1 deletions

View File

@ -94,7 +94,20 @@ class CookedPostProcessor
def get_size_from_attributes(img)
w, h = img["width"].to_i, img["height"].to_i
return [w, h] if w > 0 && h > 0
return [w, h] unless w <= 0 || h <= 0
# if only width or height are specified attempt to scale image
if w > 0 || h > 0
w = w.to_f
h = h.to_f
original_width, original_height = get_size(img["src"]).map {|integer| integer.to_f}
if w > 0
ratio = w/original_width
return [w.floor, (original_height*ratio).floor]
else
ratio = h/original_height
return [(original_width*ratio).floor, h.floor]
end
end
end
def get_size_from_image_sizes(src, image_sizes)