Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Making Thumbnail Image in CarrierWave

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.42k
    Comment on it

    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.

    • Generating an uploader
    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: