egzonmustafa
egzonmustafa

Reputation: 115

Image Resizing Service [Rails 5]

I'm building a project about Uploading image and resizing them, for the moment we are using gem FastImage which is perfect for getting image url. But i can't find any Resizing Gem.

What i want!

Upvotes: 0

Views: 355

Answers (1)

Leonardo
Leonardo

Reputation: 43

I recommend you to take a look on Carrierwave gem. It offers everything you want including the resizing part.

You can upload a image by a remote url as:

<%= form_for @user, html: { multipart: true } do |f| %>
  <p>
    <label>My Avatar URL:</label>
    <%= image_tag(@user.avatar_url) if @user.avatar? %>
    <%= f.text_field :remote_avatar_url %>
  </p>
<% end %>

And maybe resize it as:

class ImageUploader < CarrierWave::Uploader::Base

  version :resized do
    # returns an image with a maximum width of 100px 
    # while maintaining the aspect ratio
    # 10000 is used to tell CW that the height is free 
    # and so that it will hit the 100 px width first
    process :resize_to_fit => [100, 10000]
  end

end

Upvotes: 1

Related Questions