Resize the image to fit within the specified dimensions while retaining the aspect ratio of the original image. If necessary, crop the image in the larger dimension.
See even www.imagemagick.org/RMagick/doc/image3.html#resize_to_fill
the width to scale the image to
the height to scale the image to
# File lib/carrierwave/processing/image_science.rb, line 41 def resize_to_fill(new_width, new_height) ::ImageScience.with_image(self.current_path) do |img| width, height = extract_dimensions_for_crop(img.width, img.height, new_width, new_height) x_offset, y_offset = extract_placement_for_crop(width, height, new_width, new_height) img.resize( width, height ) do |i2| i2.with_crop( x_offset, y_offset, new_width + x_offset, new_height + y_offset) do |file| file.save( self.current_path ) end end end end
Resize the image to fit within the specified dimensions while retaining the original aspect ratio. The image may be shorter or narrower than specified in the smaller dimension but will not be larger than the specified values.
See even www.imagemagick.org/RMagick/doc/image3.html#resize_to_fit
the width to scale the image to
the height to scale the image to
# File lib/carrierwave/processing/image_science.rb, line 20 def resize_to_fit(new_width, new_height) ::ImageScience.with_image(self.current_path) do |img| width, height = extract_dimensions(img.width, img.height, new_width, new_height) img.resize( width, height ) do |file| file.save( self.current_path ) end end end
Resize the image to fit within the specified dimensions while retaining the original aspect ratio. Will only resize the image if it is larger than the specified dimensions. The resulting image may be shorter or narrower than specified in the smaller dimension but will not be larger than the specified values.
the width to scale the image to
the height to scale the image to
# File lib/carrierwave/processing/image_science.rb, line 66 def resize_to_limit(new_width, new_height) ::ImageScience.with_image(self.current_path) do |img| if img.width > new_width or img.height > new_height resize_to_fit(new_width, new_height) end end end