Trouble resizing the default image with Paperclip

痴心易碎 提交于 2019-11-29 08:38:40

问题


I want to be able to resize the default profile image I use with Paperclip. This is the code in my model:

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

However, the default image doesn't get resized like the user submitted images do. How can I do this?


回答1:


The solution I've been using is to specify the style for the default image:

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

Then create a default image for each style (eg: default_tiny.png that is 25x25px, etc...)

Hope that helps.




回答2:


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

when you use paperclip for resizing purpose, you will have two options for resizing

  1. # -> it crop your image with provided dimension
  2. > -> it resize your image with provided dimension

I think in your case, your image is not match with your dimension.that's why it is not getting resized



来源:https://stackoverflow.com/questions/5987751/trouble-resizing-the-default-image-with-paperclip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!