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

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

Instance Method Summary collapse

Instance Method Details

#height(style = default_style) ⇒ Object



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

def height(style = default_style)
  meta_read 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.



53
54
55
# File 'lib/paperclip-meta/attachment.rb', line 53

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
# 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))
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_write(:meta, meta_encode({}))
  end
  
end

#size_with_meta_data(style = nil) ⇒ Object

Use meta info for style if required



39
40
41
# File 'lib/paperclip-meta/attachment.rb', line 39

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

#width(style = default_style) ⇒ Object



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

def width(style = default_style)
  meta_read style, :width
end