Module: AnotherUploader::ImageProcessing

Included in:
Upload
Defined in:
lib/another_uploader/image_processing.rb

Instance Method Summary collapse

Instance Method Details

#calculate_sizes(style) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/another_uploader/image_processing.rb', line 18

def calculate_sizes(style)
  if image_ratio > 1
    @image_width ||= [width, max_dimension(style)].min
    @image_height ||= (@image_width / image_ratio).round
  else
    @image_height ||= [height, max_dimension(style)].min
    @image_width ||= (@image_height * image_ratio).round
  end
  @image_size ||= "#{@image_width.to_i}x#{@image_height.to_i}"
end

#dimension(dim, style) ⇒ Object



3
4
5
6
7
8
# File 'lib/another_uploader/image_processing.rb', line 3

def dimension dim, style
  return nil unless self[dim]
  return self[dim] if style == :default
  calculate_sizes(style.to_sym)
  return instance_variable_get("@image_#{dim}").to_i
end

#image_ratioObject



10
11
12
# File 'lib/another_uploader/image_processing.rb', line 10

def image_ratio
  @image_ratio ||= width.to_f / height.to_f
end

#max_dimension(style) ⇒ Object



14
15
16
# File 'lib/another_uploader/image_processing.rb', line 14

def max_dimension(style)
  @max_dimension ||= Paperclip::Geometry.parse(self.local.styles[style][:geometry]).width.to_f
end