I have a photo-sharing application that allows the user to drag and drop images, which are then processed in a slow motion and displayed in the gallery. I'm having trouble resolving iPhone image orientation issues. I have the following code:
initializers / auto _orient.rb
module Paperclip class AutoOrient < Paperclip::Processor def initialize(file, options = {}, *args) @file = file end def make( *args ) dst = Tempfile.new([@basename, @format].compact.join(".")) dst.binmode Paperclip.run('convert',"#{File.expand_path(@file.path)} -auto-orient #{File.expand_path(dst.path)}") return dst end end end
models /picture.rb
class Picture < ActiveRecord::Base belongs_to :gallery before_create :generate_slug after_create :send_to_delayed_job validates :slug, :uniqueness => true scope :processing, where(:processing => true) attr_accessible :image has_attached_file :image, :styles => { :huge => "2048x1536>", :small => "800x600>", :thumb => "320x240>" }, :processors => [:auto_orient, :thumbnail] before_post_process :continue_processing ... def process self.image.reprocess! self.processing = false self.save(:validations => false) end private def continue_processing if self.new_record? !self.processing end end def send_to_delayed_job Delayed::Job.enqueue ImageProcess.new(self.id), :queue => 'paperclip' end end
models / image _process.rb
class ImageProcess < Struct.new(:picture_id) def perform picture = Picture.find(self.picture_id) picture.process end end
If I comment on the after_create :send_to_delayed_job lines after_create :send_to_delayed_job and before_post_process , that is, the processing is done in place, the automatic orientation process works. But, when I transfer it to the delayed work, automatic orientation does not occur, just resizing.
Does anyone have any ideas?
EDIT
This is getting weird. I moved to Carrierwave and a carrierwave_backgrounder gem. Ignoring background tasks at the moment, in my image_uploader.rb :
there is the following:
def auto_orient manipulate! do |img| img.auto_orient! img end end version :huge do process :auto_orient process resize_to_fit: [2048,1536] end
It works. Images are in the correct orientation.
Now, if I add process_in_background :image to my picture.rb file according to the instructions for the carrier wave_backgrounder, auto_orient does not work.
Now I will try to use the store_in_background method to find out does not matter.