How do you have a default Gravatar that is external and that actually resizes properly?

喜你入骨 提交于 2019-12-04 10:10:34

Gravatar will not resize your default image for you. I assume that it just 302s to the ulr gave as a default if it does not find an gravatar for the email you gave it. It looks like the 's' parameter in the iconfinder url is for the size you are trying to grab but that icon does not have a size of 50px available only 128, 256, and 512

Example:

http://www.iconfinder.com/ajax/download/png/?id=43350&s=256

If you wanted a 50px and 80px versions of the icon I would save it to your applications public/image directory as default_gravatar_50.png and default_gravatar_80.png respectively and change your method like so.

end

def gravatar_for(user, options = {})
  options = { :size => 50 }.merge(options)
  options[:default] = image_tag("default_gravatar_#{options[:size]}.png
  gravatar_image_tag(user.email.downcase,
                     :alt => user.full_name,
                     :class => 'gravatar',
                     :gravatar => options)
end

Or if you find an icon on icon finder that is the size(s) you like change the setting of the default option like so.

options[:default] = "http://www.iconfinder.com/ajax/download/png/?id=43350&s=#{options[:size]}"

Iconfinder here. You don't want to link to the download script. Instead just grab the URL to the image it self so you wan't get a lot of header information.

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