Module: CarrierWave::ImageScience
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/carrierwave/processing/image_science.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#resize_to_fill(new_width, new_height) ⇒ Object
Resize the image to fit within the specified dimensions while retaining the aspect ratio of the original image.
-
#resize_to_fit(new_width, new_height) ⇒ Object
Resize the image to fit within the specified dimensions while retaining the original aspect ratio.
-
#resize_to_limit(new_width, new_height) ⇒ Object
Resize the image to fit within the specified dimensions while retaining the original aspect ratio.
Instance Method Details
#resize_to_fill(new_width, new_height) ⇒ Object
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
Parameters
- width (Integer)
-
the width to scale the image to
- height (Integer)
-
the height to scale the image to
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/carrierwave/processing/image_science.rb', line 57 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_to_fit(new_width, new_height) ⇒ Object
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
Parameters
- width (Integer)
-
the width to scale the image to
- height (Integer)
-
the height to scale the image to
36 37 38 39 40 41 42 43 |
# File 'lib/carrierwave/processing/image_science.rb', line 36 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_to_limit(new_width, new_height) ⇒ Object
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.
Parameters
- width (Integer)
-
the width to scale the image to
- height (Integer)
-
the height to scale the image to
82 83 84 85 86 87 88 |
# File 'lib/carrierwave/processing/image_science.rb', line 82 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 |