LoginSignup
1

posted at

updated at

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

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

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

結論

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

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

参考

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
What you can do with signing up
1