Rails 4 Resizing and Cropping Images similar to Facebook

送分小仙女□ 提交于 2019-12-23 16:17:26

问题


I currently use yanex rich content api to get pages summaries in my rails 4 app. What is the best way to format the images similar to how Facebook does it? Facebook sometimes shows an image with the size of 377px by 177px which they crop and scale the original so it can maintain the aspect ratio. They also show images to fit a 90px by 90px div which just scale (no crop) the original image.

you can see examples of the two different sizes here: https://www.facebook.com/pages/Coffee-News-Now/209732789217831?ref=hl

Should I use imagemagick and if so what is the logic to determine which image size to show (larger image: cropped/scaled or smaller image: scaled)?


回答1:


Try looking at paperclip gem.

You can automate thumbnail generation.

has_attached_file :avatar, :styles => { :thumb => ["32x32#", :png] }


来源:https://stackoverflow.com/questions/21259547/rails-4-resizing-and-cropping-images-similar-to-facebook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!