How do I configure eager resize on server side upload with rails 4 and attachinary?
Hello friends,
Just signed up with cloudinary and the service is great.
I have a problem with eager resize on upload. The images are getting uploaded but not resized to 500x500. I am using attachinary server side (not jquery fileupload) and rails 4.
Should the "eager" configuration be in the model as part of has_attachment or in the view as an argument to attachinary_file_field?
Can you point me to a demo or let me know what the basic configurations would be for this functionality (scaled resize to 500x500)?
One last question: if the image being uploaded is smaller than 500x500, how can I ignore the eager resizing?
Thanks!
-
Uploading an image with eager transformations will upload the file as is, while generating another derived image (the transformed version).
If you want the original to be transformed, you can use incoming transformations which transform your images before storing them in your account.Any Cloudinary's upload parameters can be specified when uploading from the server-side using Attachinary.
When calling the attribute assignment method with a file, path or remote URL, additional optional parameters can be specified. These parameters include incoming transformations ones as well as eager transformations.For example, incoming transformation limiting to 1000x1000. In this example,
article
is an ActiveRecord model object andphoto
is an Attachinary mounted attribute.article.send(:photo=, File.open("/home/sample.jpg", 'rb'), :width => 1000, :height => 1000, :crop => :limit)
Another example with two eager transformations:
article.send(:photo=, File.open("/home/sample.jpg", 'rb'), :eager => [{:width => 200, :height => 100, :crop => :fill, :gravity => :face}, {:quality => 80, :effect => :sepia}])
Here's some details: https://github.com/assembler/attachinary#additional-methods
Regarding the last question, you can use the
limit
crop mode which will tell Cloudinary to resize down the uploaded image if it's bigger than the specified dimensions, and leave it untouched otherwise.0
Post is closed for comments.
Comments
1 comment