【问题标题】:Attachment_Fu thumbnail widthAttachment_Fu 缩略图宽度
【发布时间】:2010-11-07 04:55:15
【问题描述】:

关于如何获取缩略图的宽度和高度的任何想法? 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 %>

【问题讨论】:

    标签: ruby-on-rails ruby thumbnails attachment-fu


    【解决方案1】:

    默认情况下,attachment_fu 仅从表中加载父照片以获取诸如 url 之类的信息。当您将缩略图选项传递给它时,它只是在扩展名之前的文件名末尾附加适当的大小。

    如果您想获得大小,您需要在表格中查找它,例如 Photo.find_by_parent_id(photo.id, :conditions => ['thumbnail = ?', 'thumbnail_class_name' ]).宽度

    你最好事先知道照片的宽度,至少如果你打算将它用于任何经常运行的东西。

    【讨论】:

      【解决方案2】:
       :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 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-06-14
        • 2015-03-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多