How do I configure eager resize on server side upload with rails 4 and attachinary?

Comments

1 comment

  • Avatar
    Itay Taragano

    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 and  photo  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
    Comment actions Permalink

Please sign in to leave a comment.