As we know that in almost all web applications we use images then be it larger images or thumbnails
So for these functionalities we use Carrierwave gem. This gem helps us with uploading images and files.
With the help of carrier wave gems we can upload all sorts of images like larger images, thumbnails .
We can even adjust the size of these pictures according to our requirement.
For these we need to go through the following steps
- Adding the carrierwave gem to the gem file
gem 'carrierwave'
and then run bundle install.
rails generate uploader picture
This will generate a file app/uploaders/picture_uploader.rb
- Now in this uploader file uncomment this code
#Create different versions of your uploaded files:
version :thumb do
process :resize_to_fit => [50, 50]
end
This code is for the resizing of the picture.
- Now we also have to uncomment minimagick in the uploader file so as to use the resizing functionality
include CarrierWave::MiniMagick
- Now at last we just have to use the thumbnail object at the view side so as to tell the image tag to use mini magick
<%= image_tag (user.picture.thumb) if user.picture? %>
So this is how you use mini magick if u want your pictures to be displayed as thumbnails in your rails app.
0 Comment(s)