msn email google-talk twitter tumblr flickr

exifr

项目要用这个功能 顺便记一下

 ~/Desktop >irb
    irb(main):001:0> require 'exifr'
    LoadError: no such file to load -- exifr
    from (irb):1:in `require'
    from (irb):1
    irb(main):002:0> require 'rubygems'
    => true
    irb(main):003:0> require 'exifr'
    => true
    irb(main):004:0> EXIFR::JPEG.new('/home/joey/Desktop/1111.jpeg').exif?
    => true
    irb(main):005:0> EXIFR::JPEG.new('/home/joey/Desktop/1111.jpeg').width
    => 600
    irb(main):006:0> a=EXIFR::JPEG.new('/home/joey/Desktop/1111.jpeg')
    => #<EXIFR::JPEG:0xb7543604 @exif=[{:white_balance=>0, :date_time_original=>Sun Nov 01 11:29:04 +0800 2009, :pixel_x_dimension=>960, :make=>"Nokia", :digital_zoom_ratio=>Rational(1, 1), :ycb_cr_positioning=>1, :date_time_digitized=>Sun Nov 01 11:29:04 +0800 2009, :pixel_y_dimension=>1280, :model=>"5310 XpressMusic", :software=>"V 07.01", :scene_capture_type=>0, :custom_rendered=>0, :orientation=>#<EXIFR::TIFF::Orientation:0xb75578c0 @type=:TopLeft, @value=1>, :x_resolution=>Rational(300, 1), :exposure_mode=>0, :color_space=>1, :y_resolution=>Rational(300, 1), :resolution_unit=>2}], @bits=8, @width=600, @height=800>
    irb(main):007:0> a.date_time_digitized
    => Sun Nov 01 11:29:04 +0800 2009
    irb(main):008:0> a.date_time_original
    => Sun Nov 01 11:29:04 +0800 2009
    irb(main):009:0

show一下model里的pp回调

   1      # PAPERCLIP Callback after styles processing (thumbnails).
   2    # Use this to extract Exif metadata from the image
   3    def post_process_image
   4      img_meta = EXIFR::JPEG.new(photo.queued_for_write[:original].path)
   5      return unless img_meta
   6      logger.debug "Photo EXIF: " + img_meta.inspect
   7      self.date_time_original = img_meta.date_time_original.to_s
   8      self.model = img_meta.model.to_s
   9      self.exposure_time = img_meta.exposure_time.to_s
  10      self.focal_length = img_meta.focal_length.to_s
  11      self.max_aperture_value = img_meta.max_aperture_value.to_s
  12      self.exposure_bias_value = img_meta.exposure_bias_value.to_s 
  13      # also have width and height. See http://exifr.rubyforge.org/api/index.html for details
  14    end

字段备注
t.datetime :date_time_original #创建时间
t.string :model #型号指设备型号
t.string :exposure_time #曝光时间
t.string :focal_length #焦距
t.string :max_aperture_value #最大光圈
t.string :exposure_bias_value #曝光补偿