Home Dynamic size styling in paperclip
Reply: 2

Dynamic size styling in paperclip

Ruturaj Bisure
Ruturaj Bisure Published in 2018-01-04 07:27:20Z

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

sam Reply to 2018-01-04 10:04:31Z

As my thought you want to set image size whenever you are creating and updating object. You can try this one or this one .

Ruturaj Bisure
Ruturaj Bisure Reply to 2018-01-04 13:18:52Z

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)
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.348245 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO