FEATURE: new site setting
This commit is contained in:
parent
3aa165d3b6
commit
92e6446f0f
|
@ -6,8 +6,12 @@ module Jobs
|
||||||
path = args[:path]
|
path = args[:path]
|
||||||
return unless File.exists?(path)
|
return unless File.exists?(path)
|
||||||
|
|
||||||
|
opts = {
|
||||||
|
allow_animation: true,
|
||||||
|
force_aspect_ratio: SiteSetting.enforce_square_emoji
|
||||||
|
}
|
||||||
# make sure emoji aren't too big
|
# make sure emoji aren't too big
|
||||||
OptimizedImage.downsize(path, path, 60, 60, true)
|
OptimizedImage.downsize(path, path, 60, 60, opts)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ class OptimizedImage < ActiveRecord::Base
|
||||||
FileUtils.cp(original_path, temp_path)
|
FileUtils.cp(original_path, temp_path)
|
||||||
resized = true
|
resized = true
|
||||||
else
|
else
|
||||||
resized = resize(original_path, temp_path, width, height, opts[:allow_animation])
|
resized = resize(original_path, temp_path, width, height, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
if resized
|
if resized
|
||||||
|
@ -81,9 +81,9 @@ class OptimizedImage < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.resize_instructions(from, to, width, height, allow_animation=false)
|
def self.resize_instructions(from, to, width, height, opts={})
|
||||||
# NOTE: ORDER is important!
|
# NOTE: ORDER is important!
|
||||||
if allow_animation && from =~ /\.GIF$/i
|
if !!opts[:allow_animation] && from =~ /\.GIF$/i
|
||||||
%W{
|
%W{
|
||||||
#{from}
|
#{from}
|
||||||
-coalesce
|
-coalesce
|
||||||
|
@ -108,14 +108,17 @@ class OptimizedImage < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.downsize_instructions(from, to, max_width, max_height, allow_animation=false)
|
def self.downsize_instructions(from, to, max_width, max_height, opts={})
|
||||||
if allow_animation && from =~ /\.GIF$/i
|
dimensions = "#{max_width}x#{max_height}"
|
||||||
|
dimensions += !!opts[:force_aspect_ratio] ? "\\!" : "\\>"
|
||||||
|
|
||||||
|
if !!opts[:allow_animation] && from =~ /\.GIF$/i
|
||||||
%W{
|
%W{
|
||||||
#{from}
|
#{from}
|
||||||
-coalesce
|
-coalesce
|
||||||
-gravity center
|
-gravity center
|
||||||
-background transparent
|
-background transparent
|
||||||
-thumbnail #{max_width}x#{max_height}\\>
|
-thumbnail #{dimensions}
|
||||||
-layers optimize
|
-layers optimize
|
||||||
#{to}
|
#{to}
|
||||||
}
|
}
|
||||||
|
@ -124,19 +127,19 @@ class OptimizedImage < ActiveRecord::Base
|
||||||
#{from}[0]
|
#{from}[0]
|
||||||
-gravity center
|
-gravity center
|
||||||
-background transparent
|
-background transparent
|
||||||
-thumbnail #{max_width}x#{max_height}\\>
|
-thumbnail #{dimensions}
|
||||||
#{to}
|
#{to}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.resize(from, to, width, height, allow_animation=false)
|
def self.resize(from, to, width, height, opts={})
|
||||||
instructions = resize_instructions(from, to, width, height, allow_animation)
|
instructions = resize_instructions(from, to, width, height, opts)
|
||||||
convert_and_optimize_with(instructions)
|
convert_and_optimize_with(instructions)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.downsize(from, to, max_width, max_height, allow_animation=false)
|
def self.downsize(from, to, max_width, max_height, opts={})
|
||||||
instructions = downsize_instructions(from, to, max_width, max_height, allow_animation)
|
instructions = downsize_instructions(from, to, max_width, max_height, opts)
|
||||||
convert_and_optimize_with(instructions)
|
convert_and_optimize_with(instructions)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1127,6 +1127,7 @@ en:
|
||||||
|
|
||||||
enable_emoji: "Enable emoji"
|
enable_emoji: "Enable emoji"
|
||||||
emoji_set: "How would you like your emoji?"
|
emoji_set: "How would you like your emoji?"
|
||||||
|
enforce_square_emoji: "Force a square aspect ratio to all emojis."
|
||||||
|
|
||||||
errors:
|
errors:
|
||||||
invalid_email: "Invalid email address."
|
invalid_email: "Invalid email address."
|
||||||
|
|
|
@ -405,6 +405,8 @@ posting:
|
||||||
default: 'emoji_one'
|
default: 'emoji_one'
|
||||||
client: true
|
client: true
|
||||||
enum: 'EmojiSetSiteSetting'
|
enum: 'EmojiSetSiteSetting'
|
||||||
|
enforce_square_emoji:
|
||||||
|
default: true
|
||||||
|
|
||||||
email:
|
email:
|
||||||
email_time_window_mins:
|
email_time_window_mins:
|
||||||
|
|
Loading…
Reference in New Issue