change to resizer

This commit is contained in:
albert
2012-02-10 17:07:49 -05:00
parent 3375cf7437
commit fff97df02d

View File

@@ -1,25 +1,17 @@
module Danbooru module Danbooru
def resize(read_path, write_path, width, height, resize_quality = 90) def resize(read_path, write_path, width, height, resize_quality = 90)
image = Magick::Image.read(read_path).first image = Magick::Image.read(read_path).first
geometry = "#{width}x>"
if width == Danbooru.config.small_image_width if width == Danbooru.config.small_image_width && image.rows < image.columns
image.change_geometry("#{width}x#{height}^") do |small_width, small_height, img| # wider than it is tall
if width > height geometry = ">x#{height}"
gravity = Magick::WestGravity end
else
gravity = Magick::NorthGravity
end
img.reseize_to_fill!(small_width, small_height, gravity) image.change_geometry(geometry) do |new_width, new_height, img|
width = small_width img.resize!(new_width, new_height)
height = small_height width = new_width
end height = new_height
else
image.change_geometry("#{width}x>") do |new_width, new_height, img|
img.resize!(new_width, new_height)
width = new_width
height = new_height
end
end end
image = flatten(image, width, height) image = flatten(image, width, height)