Skip to content

Parperclip exif wrong orientation from mobile upload

lululala edited this page Feb 9, 2017 · 1 revision

If ur image wrong orientation from mobile upload, u can add :source_file_options => { :all => '-auto-orient' }.

has_attached_file :image,
                    styles: { medium: "300x300>", thumb: "100x100>" },
                    :source_file_options => { :all => '-auto-orient' },
                    default_url: ->(attachment) { ActionController::Base.helpers.asset_path('tmp/a44.png') }

Some blog says it could be :convert_options => { :all => '-auto-orient' },but it dosen't work for me.

U can get exif info by follow those steps.

gem 'exifr'

EXIFR::JPEG.new(image.queued_for_write[:original].path)    /// in user model 

EXIF info like this {:photometric_interpretation=>2, :make=>"NIKON CORPORATION", :model=>"NIKON D810", :orientation=>#<EXIFR::TIFF::Orientation:TopLeft(1)>, :x_resolution=>(240/1), :y_resolution=>(240/1), :resolution_unit=>2, :software=>"Adobe Photoshop CS6 (Windows)", :date_time=>2016-04-30 09:21:58 +0800, :exposure_time=>(1/90), :f_number=>(8/1), :exposure_program=>1, :iso_speed_ratings=>100, :date_time_original=>2016-04-27 14:56:22 +0800, :date_time_digitized=>2016-04-27 14:56:22 +0800, :shutter_speed_value=>(1/90), :aperture_value=>8.0, :exposure_bias_value=>(-1/2), :max_aperture_value=>(3/1), :metering_mode=>5, :light_source=>0, :flash=>16, :focal_length=>(56/1), :subsec_time_original=>"06", :pixel_x_dimension=>2071, :pixel_y_dimension=>2071, :focal_plane_x_resolution=>(178211/87), :focal_plane_y_resolution=>(178211/87), :focal_plane_resolution_unit=>3, :sensing_method=>2, :custom_rendered=>0, :exposure_mode=>1, :white_balance=>0, :digital_zoom_ratio=>(1/1), :focal_length_in_35mm_film=>56, :scene_capture_type=>0, :gain_control=>0, :contrast=>1, :saturation=>0, :sharpness=>0, :subject_distance_range=>0}