Search code examples
ruby-on-railsruby-on-rails-4paperclippaperclip-validation

Dynamic size styling in paperclip


I have searched for this, I got the some idea from Resize missing.png depending upon style in paperclip but not the exact solution of the following scenario.

I have a form where user choose image size from dropdown, which is to upload and Then user upload the particular image.(I have validations for the same. used Paperclip::Geometry.from_file(image.queued_for_write[:original].path) for the same) . I want to reduce the quality of original Image using convert option like (-strip -quality 90). Is there any way to create a style for original image which will be based on the selected value from the dropdown.

For eg. I have following Image sizes in dropdown ['1230 X 615'],['1230 X 390'],['1230 X 180'],['1230 X 240'],['1230 X 30'],['1020 X 180'],['1020 X 240'],['180 X 180'],['180 X 240'],['610 X 180'],['610 X 240'],['810 X 180']

Then how to create style if user select ['1020 X 240'] size from dropdown while uploading image?

Any suggestions?

Thanks in advance


Solution

  • Thanks for help. Following approach I used and it is working fine without proc,

    The ' ' in {:large=>' '} are taking dropdown selected size by default.

    has_attached_file :image, { :styles => {:large => ''},
                                              :convert_options => { :large => '-strip -quality 80'}}.merge(SECTION_PATH).merge(BUCKET_PATH)