Skip to content

Commit

Permalink
FEATURE: new site setting
Browse files Browse the repository at this point in the history
  • Loading branch information
ZogStriP committed Feb 21, 2015
1 parent 3aa165d commit 92e6446
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
6 changes: 5 additions & 1 deletion app/jobs/regular/resize_emoji.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ def execute(args)
path = args[:path]
return unless File.exists?(path)

opts = {
allow_animation: true,
force_aspect_ratio: SiteSetting.enforce_square_emoji
}
# make sure emoji aren't too big
OptimizedImage.downsize(path, path, 60, 60, true)
OptimizedImage.downsize(path, path, 60, 60, opts)
end
end

Expand Down
25 changes: 14 additions & 11 deletions app/models/optimized_image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def self.create_for(upload, width, height, opts={})
FileUtils.cp(original_path, temp_path)
resized = true
else
resized = resize(original_path, temp_path, width, height, opts[:allow_animation])
resized = resize(original_path, temp_path, width, height, opts)
end

if resized
Expand Down Expand Up @@ -81,9 +81,9 @@ def destroy
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!
if allow_animation && from =~ /\.GIF$/i
if !!opts[:allow_animation] && from =~ /\.GIF$/i
%W{
#{from}
-coalesce
Expand All @@ -108,14 +108,17 @@ def self.resize_instructions(from, to, width, height, allow_animation=false)
end
end

def self.downsize_instructions(from, to, max_width, max_height, allow_animation=false)
if allow_animation && from =~ /\.GIF$/i
def self.downsize_instructions(from, to, max_width, max_height, opts={})
dimensions = "#{max_width}x#{max_height}"
dimensions += !!opts[:force_aspect_ratio] ? "\\!" : "\\>"

if !!opts[:allow_animation] && from =~ /\.GIF$/i
%W{
#{from}
-coalesce
-gravity center
-background transparent
-thumbnail #{max_width}x#{max_height}\\>
-thumbnail #{dimensions}
-layers optimize
#{to}
}
Expand All @@ -124,19 +127,19 @@ def self.downsize_instructions(from, to, max_width, max_height, allow_animation=
#{from}[0]
-gravity center
-background transparent
-thumbnail #{max_width}x#{max_height}\\>
-thumbnail #{dimensions}
#{to}
}
end
end

def self.resize(from, to, width, height, allow_animation=false)
instructions = resize_instructions(from, to, width, height, allow_animation)
def self.resize(from, to, width, height, opts={})
instructions = resize_instructions(from, to, width, height, opts)
convert_and_optimize_with(instructions)
end

def self.downsize(from, to, max_width, max_height, allow_animation=false)
instructions = downsize_instructions(from, to, max_width, max_height, allow_animation)
def self.downsize(from, to, max_width, max_height, opts={})
instructions = downsize_instructions(from, to, max_width, max_height, opts)
convert_and_optimize_with(instructions)
end

Expand Down
1 change: 1 addition & 0 deletions config/locales/server.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,7 @@ en:

enable_emoji: "Enable emoji"
emoji_set: "How would you like your emoji?"
enforce_square_emoji: "Force a square aspect ratio to all emojis."

errors:
invalid_email: "Invalid email address."
Expand Down
2 changes: 2 additions & 0 deletions config/site_settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,8 @@ posting:
default: 'emoji_one'
client: true
enum: 'EmojiSetSiteSetting'
enforce_square_emoji:
default: true

email:
email_time_window_mins:
Expand Down

0 comments on commit 92e6446

Please sign in to comment.