Attachment_Fu缩略图宽度
关于如何获取缩略图的宽度和高度有什么想法吗? photo.width 返回原始照片宽度。 我将缩略图的宽度存储在数据库中,我只是不确定如何访问该对象。
不起作用:
<%= image_tag photo.authenticated_s3_url(:medium),
:width => photo.width,
:height => photo.height %>
这也不起作用:
<%= image_tag photo.authenticated_s3_url(:medium),
:width => photo.authenticated_s3_url(:medium).width,
:height => photo.authenticated_s3_url(:medium).height %>
Any ideas on how to get the width and height of the thumbnail image? photo.width returns the original photos width. I am storing the width of the thumbnail in the database, I'm just not sure how to access that object.
Doesn't work:
<%= image_tag photo.authenticated_s3_url(:medium),
:width => photo.width,
:height => photo.height %>
Neither does this:
<%= image_tag photo.authenticated_s3_url(:medium),
:width => photo.authenticated_s3_url(:medium).width,
:height => photo.authenticated_s3_url(:medium).height %>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
默认情况下,attachment_fu 仅从表中加载父照片以获取 url 等信息。 当您向其传递缩略图选项时,它只是将适当的大小附加到文件名末尾的扩展名之前。
如果您想获得尺寸,则需要在表中查找,例如 Photo.find_by_parent_id(photo.id, :conditions => ['thumbnail = ?', 'thumbnail_class_name']) .width
您最好事先知道照片的宽度,至少如果您要将其用于经常运行的任何内容的话。
By default, attachment_fu only loads the parent photo from a table to get info like the url. When you pass it a thumbnail option it simply appends the appropriate size to the end of the filename before the extension.
If you want to get the size, you're going to need to look it up in the table with something like, Photo.find_by_parent_id(photo.id, :conditions => ['thumbnail = ?', 'thumbnail_class_name']).width
You're better off knowing the width of a photo beforehand, at least if you're going to be using this for anything that would be run often.
为了获得高度和宽度,这就是我要做的
To get the height and width this is what I would do