jrgifford / delayed_paperclip

Process your Paperclip attachments in the background with delayed_job or Resque.
http://www.jstorimer.com/ruby/2010/01/30/delayed-paperclip.html
MIT License
402 stars 155 forks source link

Displaying original image while processing as an option to :processing_image_url #99

Closed kamelury closed 9 years ago

kamelury commented 10 years ago

The idea of displaying the original image while processing thumbs etc. seems to be floating around. However it is not available as an option in delayed_paperclip. Is there any reason why you haven't done it already? I am thinking about contributing to delayed_paperclip and submitting a patch request with it, but I would like to know if it was considered before or maybe rejected for some reason?

My idea was to make :processing_image_url accept a symbol of a method name in the model, that would be called to calculate the path to the original image. Or another option would be to allow :original symbol as on option for :processing_image_url. I do struggle however to find the path of the original image in the paperclip attachment.

It can obviously be done in the view by checking .processing? and then displaying url(:thumb) or url(:original), but I treat it as a last resort

I would appreciate any suggestions or hints.

peachananr commented 10 years ago

Here's what I did:

process_in_background :photo, :processing_image_url => :process_image

def process_image
      options = photo.options
      options[:interpolator].interpolate(options[:url], photo, :original)
end

and everything seems to work ok at this point. Give it a go. :)

kamelury commented 10 years ago

Fantastic! Thank you soo much! That is exactly what I was looking for.

riffraff commented 10 years ago

plase correct me if I'm wrong, but while this method works it could be slightly improved.

Namely: suppose I process online the styles "large" and "small", but in background I process "thumbnail", "hd", "landscape", "vignette" etc..

It would be great to be able to return a different fallback depending on which style is being currently requested, e.g.

def process_image fmt
      options = photo.options
      large_formats = %i[hd landscape desktop retina]
      fallback_format = large_formats.include?(fmt) ? :large : :small 
      options[:interpolator].interpolate(options[:url], photo, fallback_format)
end

Maybe this is already possible but I have not understood how :)