Attachment_Fu缩略图宽度

发布于 2024-07-26 17:23:18 字数 512 浏览 3 评论 0原文

关于如何获取缩略图的宽度和高度有什么想法吗? 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

醉城メ夜风 2024-08-02 17:23:18

默认情况下,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.

掩于岁月 2024-08-02 17:23:18
 :thumbnails => { :crop_200x200 => 'c200x200',
              :default_200x200 => '200x200',
              :ex_200x200 => '200x200!',
              :gt_200x200 => '200x200>',
              :lt_200x200 => '200x200<'}

为了获得高度和宽度,这就是我要做的

tname = 'crop_200x200'
height= @picture.thumbnails.select{ |r| r.thumbnail ==  tname }.first.height 
width= @picture.thumbnails.select{ |r| r.thumbnail == tname }.first.width 
 :thumbnails => { :crop_200x200 => 'c200x200',
              :default_200x200 => '200x200',
              :ex_200x200 => '200x200!',
              :gt_200x200 => '200x200>',
              :lt_200x200 => '200x200<'}

To get the height and width this is what I would do

tname = 'crop_200x200'
height= @picture.thumbnails.select{ |r| r.thumbnail ==  tname }.first.height 
width= @picture.thumbnails.select{ |r| r.thumbnail == tname }.first.width 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文