2009-07-01 45 views
0

有關如何獲取縮略圖圖像的寬度和高度的任何想法? photo.width返回原始照片的寬度。我將縮略圖的寬度存儲在數據庫中,我只是不確定如何訪問該對象。附件_FU縮略圖寬度

不起作用:

<%= 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 %> 

回答

1

通過默認情況下,attachment_fu只會從表中加載父照片獲取網址等信息。當你傳遞一個縮略圖選項時,它會在擴展名之前的文件名末尾附加適當的大小。

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

你最好事先知道照片的寬度,至少如果你打算將這個用於任何經常運行的東西。

0
: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 
相關問題