4 def user_image(user, options = {})
5 options[:class] ||= "user_image border border-secondary-subtle bg-body"
8 if user.image_use_gravatar
9 user_gravatar_tag(user, options)
10 elsif user.avatar.attached?
11 user_avatar_variant_tag(user, { :resize_to_limit => [100, 100] }, options)
13 image_tag "avatar.svg", options.merge(:width => 100, :height => 100)
17 def user_thumbnail(user, options = {})
18 options[:class] ||= "user_thumbnail border border-secondary-subtle bg-body"
21 if user.image_use_gravatar
22 user_gravatar_tag(user, options.merge(:size => 50))
23 elsif user.avatar.attached?
24 user_avatar_variant_tag(user, { :resize_to_limit => [50, 50] }, options)
26 image_tag "avatar.svg", options.merge(:width => 50, :height => 50)
30 def user_thumbnail_tiny(user, options = {})
31 options[:class] ||= "user_thumbnail_tiny border border-secondary-subtle bg-body"
34 if user.image_use_gravatar
35 user_gravatar_tag(user, options.merge(:size => 50))
36 elsif user.avatar.attached?
37 user_avatar_variant_tag(user, { :resize_to_limit => [50, 50] }, options)
39 image_tag "avatar.svg", options.merge(:width => 50, :height => 50)
43 def user_image_url(user, options = {})
44 if user.image_use_gravatar
45 user_gravatar_url(user, options)
46 elsif user.avatar.attached?
47 polymorphic_url(user_avatar_variant(user, :resize_to_limit => [100, 100]), :host => Settings.server_url)
49 image_url("avatar.svg")
53 # External authentication support
56 image_tag "openid.svg", :size => "24", :alt => t("application.auth_providers.openid_logo_alt"), :class => "align-text-bottom"
59 def auth_button(name, provider, options = {})
61 image_tag("#{name}.svg",
62 :alt => t("application.auth_providers.#{name}.alt"),
63 :class => "rounded-1",
65 auth_path(options.merge(:provider => provider)),
67 :class => "auth_button btn btn-light mx-1 p-2 d-block",
68 :title => t("application.auth_providers.#{name}.title")
72 def auth_button_preferred(name, provider, options = {})
74 image_tag("#{name}.svg",
75 :alt => t("application.auth_providers.#{name}.alt"),
76 :class => "rounded-1 me-3",
77 :size => "24") + t("application.auth_providers.#{name}.title"),
78 auth_path(options.merge(:provider => provider)),
80 :class => "auth_button btn btn-outline-secondary fs-6 border rounded py-2 px-4 d-flex justify-content-center align-items-center",
81 :title => t("application.auth_providers.#{name}.title")
87 # Local avatar support
88 def user_avatar_variant_tag(user, variant_options, options)
89 if user.avatar.variable?
90 variant = user.avatar.variant(variant_options)
91 # https://stackoverflow.com/questions/61893089/get-metadata-of-active-storage-variant/67228171
92 if variant.send(:processed?)
93 metadata = variant.processed.send(:record).image.blob.metadata
95 options[:width] = metadata["width"]
96 options[:height] = metadata["height"]
99 image_tag variant, options
101 image_tag user.avatar, options
105 def user_avatar_variant(user, options)
106 if user.avatar.variable?
107 user.avatar.variant(options)
115 # See http://en.gravatar.com/site/implement/images/ for details.
116 def user_gravatar_url(user, options = {})
117 size = options[:size] || 100
118 hash = Digest::MD5.hexdigest(user.email.downcase)
119 default_image_url = image_url("avatar_large.png")
120 "#{request.protocol}www.gravatar.com/avatar/#{hash}.jpg?s=#{size}&d=#{u(default_image_url)}"
123 def user_gravatar_tag(user, options = {})
124 url = user_gravatar_url(user, options)
125 options[:height] = options[:width] = options.delete(:size) || 100
126 image_tag url, options