Reputation: 15257
I am using Ruby on Rails and the Paperclip gem and I would like to rotate an image before it is stylized and saved on my server.
For example, if in my model I have:
has_attached_file :avatar,
:styles => {
:thumb => ["50x50#", :jpg],
:small => ["100x100>", :jpg],
:medium => ["100x100>", :jpg] }
I would like to implement these steps:
How can I implement these steps in a RoR application?
I've seen the Railcast 182... I would not add third-party software, but do the implementation myself, for example with a new view file, AJAX approach (RJS) and ImageMagick libraries.
P.S.: I read about Paperclip "processors" but I am still not able to implement those. Can someone help me?
Upvotes: 1
Views: 1530
Reputation: 831
Ryan Bates explains how to set-up a similar series of steps, except for cropping:
http://railscasts.com/episodes/182-cropping-images
What I would do is try to adapt what he did for rotation instead. So, for the javascript, you can use something like this:
http://wilq32.adobeair.pl/jQueryRotate/Wilq32.jQueryRotate.html
I might provide a slider for the user input. They can freely rotate the image, and then submit whatever angle they end up settling on.
On the Rails side, keep track of the angle of rotation (instead of the cropping dimensions) and then send that to a rotation processor. (Look at how the cropping processor is done on the Railscast).
The processor will use the "-rotate" operator instead of "-crop."
And... there you have it. Obviously I didn't go into all of the specifics, but the Railscast should explain the process pretty well, and from there it is just a matter of adapting it for a different ImageMagick operation.
Upvotes: 1
Reputation: 6642
I don't believe what you are trying to achieve on the client-side is completely achievable using just Rails, it is going to require some javascript. I've used jcrop http://deepliquid.com/content/Jcrop.html in the past to do the resize/crop on the client side before the image is uploaded to the service. I'd probably look into a solution like this or similar.
Upvotes: 1