Rails 4调整大小和裁剪类似于Facebook的图像 [英] Rails 4 Resizing and Cropping Images similar to Facebook

查看:106
本文介绍了Rails 4调整大小和裁剪类似于Facebook的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用yanex内容丰富的api来获取我的rails 4 app中的页面摘要。格式化图像的最佳方式是什么,类似于Facebook的方式? Facebook有时会显示尺寸为377像素×177像素的图像,它们会裁剪并缩放原始图像,以便保持宽高比。它们还显示适合90px乘90px div的图像,它只是缩放(无裁剪)原始图像。

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.

您可以在此处查看两种不同尺寸的示例: https://www.facebook.com/pages/Coffee-News-Now/209732789217831?ref=hl

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

我应该使用imagemagick吗?若是,那么确定要显示的图像尺寸的逻辑是什么(较大的图像:裁剪/缩放或较小的图像:缩放)?

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)?

推荐答案

尝试查看 paperclip gem。

您可以自动生成缩略图。

You can automate thumbnail generation.

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

这篇关于Rails 4调整大小和裁剪类似于Facebook的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆