Module: AttachmentSaver::Processors::MiniMagick::Operations

Includes:
Image::Operations
Defined in:
lib/processors/mini_magick.rb

Instance Method Summary collapse

Methods included from Image::Operations

#cover_and_crop, #expand_to_fit, #scale_by, #scale_dimensions_to_fit, #scale_to_cover, #scale_to_fit, #shrink_to_fit, #squish

Instance Method Details

#crop_to(new_width, new_height, &block) ⇒ Object

crops to the center



92
93
94
95
96
97
98
99
# File 'lib/processors/mini_magick.rb', line 92

def crop_to(new_width, new_height, &block) # crops to the center
  left = (width - new_width)/2
  right = (height - new_height)/2
  image = dup
  image << "-crop #{new_width}x#{new_height}+#{left}+#{right} +repage" # mini_magick's #crop doesn't support the repage flag
  image.extend Operations
  block.call(image)
end

#file_type_extensionObject



74
75
76
77
78
79
# File 'lib/processors/mini_magick.rb', line 74

def file_type_extension
  case format.downcase
    when 'jpeg' then 'jpg'
    else format.downcase
  end
end

#formatObject

cached as each call to [] results in a process execution!



81
# File 'lib/processors/mini_magick.rb', line 81

def format; @__format ||= self[:format]; end

#heightObject

whereas MiniMagick may, in general.



83
# File 'lib/processors/mini_magick.rb', line 83

def height; @__height ||= self[:height]; end

#resize_to(new_width, new_height, &block) ⇒ Object



85
86
87
88
89
90
# File 'lib/processors/mini_magick.rb', line 85

def resize_to(new_width, new_height, &block)
  image = dup
  image.resize("#{new_width}x#{new_height}!")
  image.extend Operations
  block.call(image)
end

#widthObject

note that we can cache as we don’t ever modify instances -



82
# File 'lib/processors/mini_magick.rb', line 82

def width;   @__width ||= self[:width];  end