Sha256: 80e58274d84358c8c35380f77883c9b4849219ba91b5bc2d711b61ba9fafa0ed
Contents?: true
Size: 1.03 KB
Versions: 1
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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
gnawrnip-0.3.0 | lib/gnawrnip/developer.rb |