开发者

How do I tell paperclip to not save the original file?

How do I tell Paperclip not to save the original file when it is uploaded? Or even better, to开发者_如何学Go store a scaled version of the file as the original?


I believe that you can simply define a style for :original to have paperclip replace the original with that size.

:styles => { :original => '300x168>', :cropped_thumb => {:geometry => "115x70#", :jcrop => true}, ...}


Cris G's solution may be nice at most simple cases but it has limitations. consider that: style :original Paperclip process first of all others, so after that updated :original image (much smaller now) will be the source for following processing. Hence you are forced to keep :original style as best-resolutioned. The situation comes worse as you need to crop images with processor: that is the situation where you really need for real original quality. )

So I would recommend you somewhat raw (need to find out how to get every attachments of the model) solution:

after_save :reprocess_attach

private

def reprocess_attach
    if self.<atch_name>.present? && Pathname.new(self.<atch_name>.path).exist?
        self.<atch_name>.save
        File.unlink(self.<atch_name>.path)
    end
end

it doesn't care about what processing was behind the stage. It just kills original file )


Paperclip always saves an original by default, but I 'believe', that if you just remove it from your migration then it will not try and save it.

I save a scaled original on my model so that users can edit their image later. My model looks like this :

:styles => { :cropped_thumb => {:geometry => "115x70#", :jcrop => true}, :resized_thumb => {:geometry => "115x70>"}, :deal => {:geometry => "64x56#"},  
:cropped_large => {:geometry => "#{PHOTO_IMAGE_WIDTH}x#{PHOTO_IMAGE_HEIGHT}#", :jcrop => true},
:resized_large => {:geometry => "#{PHOTO_IMAGE_WIDTH}x#{PHOTO_IMAGE_HEIGHT}>"},

:orig => '300x168>',  #this is the scaled original that I call later


:cropped_orig => {:geometry => '300x168#', :jcrop => true},
:resized_orig => {:geometry => '300x168>'} },
:processors => [:jcropper]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜