2017-12-10 9 views
0

私はプロジェクトを構築していますイメージをアップロードし、のサイズを変更していますが、現在はイメージURLを取得するのに最適ですgem FastImageを使用しています。しかし、私はResizing Gemを見つけることができません。イメージサイズ変更サービス[Rails 5]

私は何をしたいですか?

    その画像の
  • ゲットサイズ
  • ゲット高さ
  • は(私はそのイメージ、無cropingを拡張することができた場合に完璧になる)その画像のサイズを変更しなさい。

答えて

1

Carrierwave gemをご覧ください。サイズ変更パーツを含め、あなたが望むものすべてを提供します。

あなたのようにリモートURLで画像をアップロードすることができます。

<%= 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 %> 

そして多分としてそれをリサイズ:あなたの答えのための

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 
+0

おかげで、私はこの手ではない(ハードコードを実行する必要があり)をモデル化する:) – egzonszo

関連する問題