LoginSignup
0
1

More than 3 years have passed since last update.

RubyOnRails 画像サイズの指定方法

Posted at

「refile」「refile-mini_magick」をインストールする

投稿フォーム等で得た画像データをリサイズすることができる機能を持っています。Gemfileにてインストールを実行。

Gemfileに記述
gem "refile", require: "refile/rails", github: 'manfe/refile'
gem "refile-mini_magick"

サイズ指定の実例

①サイズ指定のみ

<%= attachment_image_tag post_image, :image ,size:'100x100'%>

②サイズ指定+写真が無い場合のfallback設定

  <%= attachment_image_tag book.user, :profile_image, :fill, 100, 100, format: 'jpeg', fallback: "no_image.jpg", size:'100x100'  %>

③少し変わったバージョンでのサイズ指定(()の中にsize指定記述を入れる)

<%= image_tag('sample-author1.jpg',size:'100x100') %>
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1