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]
|
skip_before_filter :redirect_to_login_if_required, :check_xhr, :verify_authenticity_token, only: [:show, :show_letter]
|
||||||
|
|
||||||
def refresh_gravatar
|
def refresh_gravatar
|
||||||
|
|
||||||
user = User.find_by(username_lower: params[:username].downcase)
|
user = User.find_by(username_lower: params[:username].downcase)
|
||||||
guardian.ensure_can_edit!(user)
|
guardian.ensure_can_edit!(user)
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,8 @@ class OptimizedImage < ActiveRecord::Base
|
||||||
}.join(" ")
|
}.join(" ")
|
||||||
|
|
||||||
`convert #{instructions}`
|
`convert #{instructions}`
|
||||||
$?.exitstatus == 0
|
|
||||||
|
ImageOptim.new.optimize_image(to) rescue nil if $?.exitstatus == 0
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -29,7 +29,6 @@ class LetterAvatar
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate(username, size, opts = nil)
|
def generate(username, size, opts = nil)
|
||||||
|
|
||||||
identity = Identity.from_username(username)
|
identity = Identity.from_username(username)
|
||||||
|
|
||||||
cache = true
|
cache = true
|
||||||
|
@ -38,14 +37,10 @@ class LetterAvatar
|
||||||
size = FULLSIZE if size > FULLSIZE
|
size = FULLSIZE if size > FULLSIZE
|
||||||
filename = cached_path(identity, size)
|
filename = cached_path(identity, size)
|
||||||
|
|
||||||
if cache && File.exists?(filename)
|
return filename if cache && File.exists?(filename)
|
||||||
return filename
|
|
||||||
end
|
|
||||||
|
|
||||||
fullsize = fullsize_path(identity)
|
fullsize = fullsize_path(identity)
|
||||||
if !cache || !File.exists?(fullsize)
|
generate_fullsize(identity) if !cache || !File.exists?(fullsize)
|
||||||
generate_fullsize(identity)
|
|
||||||
end
|
|
||||||
|
|
||||||
OptimizedImage.resize(fullsize, filename, size, size)
|
OptimizedImage.resize(fullsize, filename, size, size)
|
||||||
filename
|
filename
|
||||||
|
@ -63,7 +58,6 @@ class LetterAvatar
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_fullsize(identity)
|
def generate_fullsize(identity)
|
||||||
|
|
||||||
color = identity.color
|
color = identity.color
|
||||||
letter = identity.letter
|
letter = identity.letter
|
||||||
|
|
||||||
|
@ -85,6 +79,8 @@ class LetterAvatar
|
||||||
|
|
||||||
`convert #{instructions.join(" ")}`
|
`convert #{instructions.join(" ")}`
|
||||||
|
|
||||||
|
ImageOptim.new.optimize_image(filename) rescue nil
|
||||||
|
|
||||||
filename
|
filename
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue