Sha256: 35ebfabd2b6ecd7bde28aed95d0c558769acbe104aea64a569d44acf6e29f24b
Contents?: true
Size: 1.03 KB
Versions: 7
Compression:
Stored size: 1.03 KB
Contents
require 'gnawrnip/image' module Gnawrnip class Developer def develop(file) image = Image.new(file) resize(image) if need_resize? image end private def resize(image) new_width, new_height = calculate_new_size(image.width, image.height) return if [new_width, new_height] === [image.width, image.height] image.resize(new_width, new_height) end def need_resize? !Gnawrnip.max_frame_size.nil? end # # Return new frame size (width and height). # This size is keeping original aspect ratio. # # @return [Array] New width and height size. [width, height] # def calculate_new_size(width, height) ratio = width.to_f / height.to_f target = Gnawrnip.max_frame_size return [width, height] if target > [width, height].max if ratio < 1 new_width = target * ratio new_height = target else new_width = target new_height = target / ratio end [new_width, new_height] end end end
Version data entries
7 entries across 7 versions & 1 rubygems