Module: CarrierWave::ImageScience
- Defined in:
- lib/carrierwave/processing/image_science.rb
Instance Method Summary collapse
-
#crop_resized!(geometry) ⇒ Object
Resize and crop the image so that it will have the exact dimensions passed via geometry, geometry should be a string, formatted like ‘200x100’ where the first number is the height and the second is the width.
-
#resize!(geometry) ⇒ Object
Resize the image so that it will not exceed the dimensions passed via geometry, geometry should be a string, formatted like ‘200x100’ where the first number is the height and the second is the width.
Instance Method Details
#crop_resized!(geometry) ⇒ Object
Resize and crop the image so that it will have the exact dimensions passed via geometry, geometry should be a string, formatted like ‘200x100’ where the first number is the height and the second is the width
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/carrierwave/processing/image_science.rb', line 23 def crop_resized!( geometry ) ::ImageScience.with_image(self.current_path) do |img| new_width, new_height = geometry.split('x').map{|i| i.to_i } width, height = extract_dimensions_for_crop(img.width, img.height, geometry) x_offset, y_offset = extract_placement_for_crop(width, height, geometry) 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!(geometry) ⇒ Object
Resize the image so that it will not exceed the dimensions passed via geometry, geometry should be a string, formatted like ‘200x100’ where the first number is the height and the second is the width
11 12 13 14 15 16 17 18 |
# File 'lib/carrierwave/processing/image_science.rb', line 11 def resize!( geometry ) ::ImageScience.with_image(self.current_path) do |img| width, height = extract_dimensions(img.width, img.height, geometry) img.resize( width, height ) do |file| file.save( self.current_path ) end end end |