Module: CarrierWave::ImageVoodoo
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/carrierwave_imagevoodoo.rb,
lib/carrierwave_imagevoodoo/version.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- VERSION =
"0.0.5"
Instance Method Summary collapse
- #convert(format) ⇒ Object
- #resize_to_fill(new_width, new_height) ⇒ Object
- #resize_to_fit(width, height) ⇒ Object
- #resize_to_limit(width, height) ⇒ Object
Instance Method Details
#convert(format) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/carrierwave_imagevoodoo.rb', line 31 def convert format manipulate! do |image| yield(image) if block_given? image.save "#{current_path.chomp(File.extname(f))}.#{format}" end end |
#resize_to_fill(new_width, new_height) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/carrierwave_imagevoodoo.rb', line 54 def resize_to_fill(new_width, new_height) manipulate! do |image| cols = image.width rows = image.height width, height = extract_dimensions_for_crop(image.width, image.height, new_width, new_height) x_offset, y_offset = extract_placement_for_crop(width, height, new_width, new_height) # check if if new dimensions are too small for the new image if width < new_width width = new_width height = (new_width.to_f*(image.height.to_f/image.width.to_f)).round elsif height < new_height height = new_height width = (new_height.to_f*(image.width.to_f/image.height.to_f)).round end image.resize( width, height ) do |i2| # check to make sure offset is not negative if x_offset < 0 x_offset = 0 end if y_offset < 0 y_offset = 0 end 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(width, height) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/carrierwave_imagevoodoo.rb', line 46 def resize_to_fit width, height manipulate! do |image| if (width != image.width) || (height != image.height) resize_to_fit!(image, width, height) end end end |
#resize_to_limit(width, height) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/carrierwave_imagevoodoo.rb', line 38 def resize_to_limit width, height manipulate! do |image| if (width < image.width) || (height < image.height) resize_to_fit!(image, width, height) end end end |