RoR - 回形针 - 如何设置附件的最小宽度
我的布局要求是将所有缩略图保持在 80px 高度,不更高,不更小。在我的模型中,我将样式设置为 :thumb=> “500x80>”
,所以基本上几乎所有不太宽的图片都会得到其高度为 80px 的完美缩影。然而,有时我的图片又窄又高,因此拇指可能具有无法点击的尺寸,例如 5x80。因此,只要缩略图没有变得太窄,我就不想裁剪图片,但我认为如果拇指的宽度变得小于 25px,我可以做出一点牺牲并裁剪它们。
所以我的问题是 - 是否可以在回形针中设置图片的最小比例,其中样式将是 "500x80>"
,超出范围它将变成诸如 "25x80#" ?
my layout's requirement is to keep all thumbnails at 80px height, not higher, not smaller. In my model I set the style to :thumb=> "500x80>"
, so basically almost every picture which is not too wide gets its perfect miniature with 80px height. Sometimes, however, my pictures are narrow and high, so the thumb can have unclickable dimensions of like 5x80. So I dont want to crop pictures as long as thumbnails are not getting crazy narrow, but I think I can make a little sacrifice and crop them if thumb's width is getting smaller than 25px.
So my questions is - is it possible in paperclip to set minimal proportions of a picture by which the style will be "500x80>"
and beyond that it will turn to sth like "25x80#"
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
几周前我在互联网上找到了一个很好的解决方案。忘记在哪里了,抱歉。但它看起来像这样:
I found a nice solution somewhere in the internet a couple of weeks ago. I forgot where, sorry. But it looks like this:
我不确定你如何仅使用回形针来完成此任务 - 感觉应该有某种方法可以做到这一点,不是吗?
Paperclip 只是在后台使用 imagemagick (http://www.imagemagick.org/Usage/ resize/#shrink)你可以定时执行一个作业,使用图像魔法在每晚的基础上增长那些讨厌的狭窄图像。
这是一个黑客,但我能提供的最好的主意。
祝你好运。
I'm not sure how you could accomplish this using just paperclip - feels like there should be someway to do it doesn't it?
Paperclip is just using imagemagick in the background (http://www.imagemagick.org/Usage/resize/#shrink) you could cron a job that uses image magic to grow those pesky narrow images on a nightly basis.
It's a hack, but best idea I can offer.
Good luck.