When the user updates an image, I would like to crop it to different sizes to suit different specifications in the application like a bigger size image for profile page, a smaller image for comments etc. Is there any gem available for this in rails?
Share
I would advise you to use the Paperclip gem for this. With it, you can define several sizes for your image. You do need to have ImageMagick installed for this to work. Your ruby model would have a line like this:
The default behavior is to resize to the smallest dimension and keep the aspect ratio. You can use some options to change this:
In your code you can then request the image using
image_tag @model.image.url(:small)in your view.Ryan bates has an excellent railscast on this if you want more information. Paperclip also has an extensive wiki on GitHub.