2011-05-13 73 views
10

我希望能夠調整使用Paperclip的默認配置文件圖像的尺寸。這是在我的模型代碼:使用Paperclip調整默認圖像的尺寸

has_attached_file :photo, 
    :styles => { 
    :tiny => "25x25#", 
    :thumbnail => "100x100#", 
    :small => "150x150>", 
    :medium => "300x300>" }, 
    :default_url => "/images/default.png" 

然而,默認的圖像沒有得到調整,如用戶提交的圖片做。我怎樣才能做到這一點?

回答

27

我一直在使用該解決方案是指定樣式的默認圖片:

has_attached_file :photo, 
:styles => { 
    :tiny => "25x25#", 
    :thumbnail => "100x100#", 
    :small  => "150x150>", 
    :medium => "300x300>" }, 
    :default_url => "/images/default_:style.png" 

然後創建每個樣式的默認圖像(如:default_tiny.png是25x25px,等...)

希望有幫助。

+1

+1非常漂亮和優雅的解決方案。 – sevenseacat 2011-05-13 11:33:28

+0

不錯的做法,非常整齊 – 2014-12-28 21:30:36

0
has_attached_file :photo, 
    :styles => { 
    :tiny => "25x25#", 
    :thumbnail => "100x100#", 
    :small => "150x150>", 
    :medium => "300x300>" }, 
    :default_url => "/images/default.png" 

當您使用回形針用於調整的目的,您將有兩個選項調整

  1. # - >它調整您所提供的圖像 - >它提供的尺寸
  2. >裁剪圖像維

我覺得你的情況,你的形象不匹配您的dimension.that就是爲什麼它是沒有得到調整

+0

呵呵?你能否更好地解釋這一點。 – user730569 2011-05-13 06:16:08

+0

例如你的圖像尺寸是300x300,你嘗試在400X400中調整大小。然後它不會工作 – Hitesh 2011-05-13 06:20:18

+0

你意識到我只是在談論默認圖像,對吧?圖片在/images/default.png – user730569 2011-05-13 06:21:38