如何拥有一个默认的外部 Gravatar 并且能够正确调整大小?
为了在我的 Rails3 应用程序中实现 Gravatar,我使用了 gravatar_image_tag gem一个助手,但我在混合 2 个配置选项时遇到问题:
- 如果用户的电子邮件中没有附加头像,则会呈现默认图像;但我希望它引用外部文件(例如,
http://www.iconfinder.com/ajax/download/png/?id=43350&s=128
而不是:identicon
或其他) - 我还希望图像能够调整大小,例如 50px。
独立地,这两个选项都按预期工作,但是当我将它们放在一起时:
def gravatar_for(user, options = { :default => 'http://www.iconfinder.com/ajax/download/png/?id=43350&s=128', :size => 50 }) gravatar_image_tag(user.email.downcase, :alt => user.full_name, :class => 'gravatar', :gravatar => options) end
不应用大小选项,并且头像以全尺寸渲染(在本例中为 128px)。
我做错了什么,或者我怎样才能实现这种组合?
To implement Gravatar in my Rails3 application, I'm using the gravatar_image_tag gem in a helper, but I'm having issues when mixing 2 config options:
- If the user doesn't have a gravatar attached to his email a default image is rendered; but I want it to reference an external file (e.g.,
http://www.iconfinder.com/ajax/download/png/?id=43350&s=128
instead of:identicon
or others) - I also want the image to be resized on the fly to, let's say 50px.
Independently, both options work as expected, but when I put them together:
def gravatar_for(user, options = { :default => 'http://www.iconfinder.com/ajax/download/png/?id=43350&s=128', :size => 50 }) gravatar_image_tag(user.email.downcase, :alt => user.full_name, :class => 'gravatar', :gravatar => options) end
the size option is not applied, and the gravatar gets rendered in it's full size (128px in this case).
What am I doing wrong, or how can I achieve this combination?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Gravatar 不会为您调整默认图像的大小。我假设如果它没有找到您提供的电子邮件的头像,则默认情况下它只会对 ulr 进行 302 秒。看起来 iconfinder url 中的 's' 参数是针对您想要获取的大小,但该图标没有 50px 的大小,仅提供 128、256 和 512
示例:
如果您想要 50px 和 80px 版本我会将其图标保存到您的应用程序 public/image 目录中,分别作为 default_gravatar_50.png 和 default_gravatar_80.png 并像这样更改您的方法。
或者
,如果您在图标查找器上找到您喜欢的大小的图标,请像这样更改默认选项的设置。
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:
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
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.
图标查找器在这里。您不想链接到下载脚本。相反,只需获取图像本身的 URL,这样您就不会获得大量标头信息。
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.