Module: Paperclip::Meta::Attachment::InstanceMethods

Defined in:
lib/paperclip-meta/attachment.rb

Instance Method Summary collapse

Instance Method Details

#height(*args) ⇒ Object



46
47
48
# File 'lib/paperclip-meta/attachment.rb', line 46

def height(*args)
  meta_read((args.first || default_style), :height)
end

#image_size(style = default_style) ⇒ Object

Return image dimesions (“WxH”) for given style name. If style name not given, return dimesions for default_style.



56
57
58
# File 'lib/paperclip-meta/attachment.rb', line 56

def image_size(style = default_style)
  "#{width(style)}x#{height(style)}"
end

#post_process_styles_with_meta_data(*style_args) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/paperclip-meta/attachment.rb', line 19

def (*style_args)
  (*style_args)
  return unless instance.respond_to?(:"#{name}_meta=")

  meta = {}
  @queued_for_write.each do |style, file|
    begin
      geo = Geometry.from_file file
      meta[style] = {:width => geo.width.to_i, :height => geo.height.to_i, :size => file.size }
    rescue Paperclip::Errors::NotIdentifiedByImageMagickError
      meta[style] = {}
    end
  end

  return if meta == {}

  instance.send("#{name}_meta=", meta_encode(meta))
  instance.class
    .where(instance.class.primary_key => instance.id)
    .update_all("#{name}_meta" => meta_encode(meta))
end

#save_with_meta_dataObject



12
13
14
15
16
17
# File 'lib/paperclip-meta/attachment.rb', line 12

def 
  if @queued_for_delete.any? && @queued_for_write.empty? && instance.respond_to?(:"#{name}_meta=")
    instance_write(:meta, meta_encode({}))
  end
  
end

#size_with_meta_data(passed_style = nil) ⇒ Object

Use meta info for style if required



42
43
44
# File 'lib/paperclip-meta/attachment.rb', line 42

def (passed_style = nil)
  passed_style ? meta_read(passed_style, :size) : 
end

#width(*args) ⇒ Object



50
51
52
# File 'lib/paperclip-meta/attachment.rb', line 50

def width(*args)
  meta_read((args.first || default_style), :width)
end