LoginSignup
4
2

More than 1 year has passed since last update.

【rails】image_tagで超簡単に画像を丸く(円形に)くり抜いて表示する方法

Last updated at Posted at 2022-04-27

久々に、railsのerbを使う機会があり、画像を丸く(円形に)くり抜いて表示する要件があったので調べました。

左の画像を、アスペクト比を崩さずに右のように円形にくり抜いて表示したいです。

結論

<%= image_tag "画像パス or URL", style: "border-radius: 50%; width: 200px; height: 200px; object-fit:cover;" %>

widthheihgtは同じ値にしてください。
※ cssは都合上インラインスタイルでやってます。一般的にはcssファイルに分けた方がよいそうです。

参考

4
2
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
4
2