问题
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
- # -> it crop your image with provided dimension
- > -> 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