Module: Paperclip::Dimension

Defined in:
lib/version.rb,
lib/paperclip-dimension.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

VERSION =
'0.2.1'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



5
6
7
# File 'lib/paperclip-dimension.rb', line 5

def self.included(klass)
  klass.extend Paperclip::Dimension::ClassMethods
end

Instance Method Details

#save_dimensions_for(name) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/paperclip-dimension.rb', line 34

def save_dimensions_for(name)
  if self.class.respond_to?(:attachment_definitions)
    # for Paperclip version <= 3.4.2 and >= 3.5.1
    opts = self.class.attachment_definitions[name]
  else
    # for Paperclip version 3.5.0
    opts = ::Paperclip::Tasks::Attachments.definitions_for(self.class)[name]
  end

  styles = [:original]
  styles += opts[:styles].keys if opts[:styles]
  dimension_hash = {}
  styles.each do |style|
    attachment = self.send name
    geo = ::Paperclip::Geometry.from_file(attachment.queued_for_write[style])
    dimension_hash[style.to_s] = [ geo.width.to_i, geo.height.to_i ]
  end
  self.send "#{name}_dimensions=", dimension_hash
end