使用 Attachment_fu 调整 Flickr 样式大小
我希望 Attachment_fu 能够以与 flickr、facebook 和 twitter 处理方式类似的方式调整缩略图大小:如果我想要 100x100 的缩略图,我希望缩略图恰好为 100x100,并剪掉任何多余部分,以便保留纵横比。
有什么想法吗?
I want attachment_fu to resize my thumbnails in a similar way to how flickr, facebook and twitter handle this: If I want a 100x100 thumbnail I want the thumbnail to be exactly 100x100 with any excess cropped off so that the aspect ratio is preserved.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
要设置 100x100 缩略图,请将以下内容添加到您的模型中:(
在本示例中,除了保持原始大小之外,我还创建了 100x100 缩略图,以及 800x600“大”尺寸。)
此外,请记住缩略图可能不完全是 100x100;其最大尺寸为 100x100。这意味着,如果原件的宽高比为 4:3,则缩略图将为 100x75。我不太确定这是否是您所说的“正好 100x100,剪掉任何多余部分以保留纵横比”的意思。
To set up the 100x100 thumbnails, add the following to your model:
(In this example, I am creating a 100x100 thumbnail, and also an 800x600 'large' size, in additional to keeping the original size.)
Also, keep in mind that the thumbnail might not be exactly 100x100; it will have a maximum dimension of 100x100. This means that if the original has an aspect ration of 4:3, the thumbnail would be 100x75. I'm not exactly sure if that is what you meant by "exactly 100x100 with any excess cropped off so that the aspect ratio is preserved."
将其添加到您的模型中
并将缩略图大小更改为:
来源:
http://stuff-things.net/2008/02/21/quick-and-dirty-cropping-images-with-attachment_fu/
Add this to your model
and change the thumbnail size to:
source:
http://stuff-things.net/2008/02/21/quick-and-dirty-cropping-images-with-attachment_fu/
规范中可以给出一个裁剪指令:
Memonic: '#' 看起来像裁剪工具。
编辑:更正
以前的方法适用于回形针,它具有不同的符号。
There's a cropping directive that can be given in the specification:
Memonic: '#' looks like the crop tool.
Edit: Correction
The previous method was for Paperclip which has a different notation.
我的解决方案是深入研究 Attachment_fu 插件文件夹(vendor/plugins)并编辑 rmagick_processor.rb 文件。首先,我将 resize_image 重命名为 resize_image_internal,然后添加:
我现在可以使用 'square: 100x100' 作为我的几何字符串。请注意,上面的代码假设所需的输出是平方的。
My solution was to delve into the attachment_fu plugin folder (vendor/plugins) and edit the rmagick_processor.rb file. First I renamed resize_image to resize_image_internal, then added:
I can now use 'square: 100x100' as my geometry string. Note that the above code assumes the required output is square.