mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 01:16:38 -06:00
FEATURE: optimize the hell out of letter avatars
This commit is contained in:
parent
bd13576dee
commit
609d1e05cd
@ -6,7 +6,6 @@ class UserAvatarsController < ApplicationController
|
||||
skip_before_filter :redirect_to_login_if_required, :check_xhr, :verify_authenticity_token, only: [:show, :show_letter]
|
||||
|
||||
def refresh_gravatar
|
||||
|
||||
user = User.find_by(username_lower: params[:username].downcase)
|
||||
guardian.ensure_can_edit!(user)
|
||||
|
||||
|
@ -82,7 +82,8 @@ class OptimizedImage < ActiveRecord::Base
|
||||
}.join(" ")
|
||||
|
||||
`convert #{instructions}`
|
||||
$?.exitstatus == 0
|
||||
|
||||
ImageOptim.new.optimize_image(to) rescue nil if $?.exitstatus == 0
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -29,7 +29,6 @@ class LetterAvatar
|
||||
end
|
||||
|
||||
def generate(username, size, opts = nil)
|
||||
|
||||
identity = Identity.from_username(username)
|
||||
|
||||
cache = true
|
||||
@ -38,14 +37,10 @@ class LetterAvatar
|
||||
size = FULLSIZE if size > FULLSIZE
|
||||
filename = cached_path(identity, size)
|
||||
|
||||
if cache && File.exists?(filename)
|
||||
return filename
|
||||
end
|
||||
return filename if cache && File.exists?(filename)
|
||||
|
||||
fullsize = fullsize_path(identity)
|
||||
if !cache || !File.exists?(fullsize)
|
||||
generate_fullsize(identity)
|
||||
end
|
||||
generate_fullsize(identity) if !cache || !File.exists?(fullsize)
|
||||
|
||||
OptimizedImage.resize(fullsize, filename, size, size)
|
||||
filename
|
||||
@ -63,7 +58,6 @@ class LetterAvatar
|
||||
end
|
||||
|
||||
def generate_fullsize(identity)
|
||||
|
||||
color = identity.color
|
||||
letter = identity.letter
|
||||
|
||||
@ -85,6 +79,8 @@ class LetterAvatar
|
||||
|
||||
`convert #{instructions.join(" ")}`
|
||||
|
||||
ImageOptim.new.optimize_image(filename) rescue nil
|
||||
|
||||
filename
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user