mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: don't butcher GIFs
Use 'gifsicle' instead of 'convert' to resize & optimize GIFs FIX: don't even try to fix GIFs orientation FIX: use 'allow_animated_thumbnails' site setting for user profile backgrounds & user cards
This commit is contained in:
parent
ccdcca578d
commit
d456460d33
@ -99,6 +99,7 @@ class OptimizedImage < ActiveRecord::Base
|
|||||||
def self.resize_instructions(from, to, dimensions, opts={})
|
def self.resize_instructions(from, to, dimensions, opts={})
|
||||||
# NOTE: ORDER is important!
|
# NOTE: ORDER is important!
|
||||||
%W{
|
%W{
|
||||||
|
convert
|
||||||
#{from}[0]
|
#{from}[0]
|
||||||
-gravity center
|
-gravity center
|
||||||
-background transparent
|
-background transparent
|
||||||
@ -113,17 +114,18 @@ class OptimizedImage < ActiveRecord::Base
|
|||||||
|
|
||||||
def self.resize_instructions_animated(from, to, dimensions, opts={})
|
def self.resize_instructions_animated(from, to, dimensions, opts={})
|
||||||
%W{
|
%W{
|
||||||
|
gifsicle
|
||||||
#{from}
|
#{from}
|
||||||
-coalesce
|
--colors=256
|
||||||
-gravity center
|
--resize-fit #{dimensions}
|
||||||
-thumbnail #{dimensions}^
|
--optimize=3
|
||||||
-extent #{dimensions}
|
--output #{to}
|
||||||
#{to}
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.downsize_instructions(from, to, dimensions, opts={})
|
def self.downsize_instructions(from, to, dimensions, opts={})
|
||||||
%W{
|
%W{
|
||||||
|
convert
|
||||||
#{from}[0]
|
#{from}[0]
|
||||||
-gravity center
|
-gravity center
|
||||||
-background transparent
|
-background transparent
|
||||||
@ -133,14 +135,7 @@ class OptimizedImage < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.downsize_instructions_animated(from, to, dimensions, opts={})
|
def self.downsize_instructions_animated(from, to, dimensions, opts={})
|
||||||
%W{
|
resize_instructions_animated(from, to, dimensions, opts)
|
||||||
#{from}
|
|
||||||
-coalesce
|
|
||||||
-gravity center
|
|
||||||
-background transparent
|
|
||||||
-resize #{dimensions}#{!!opts[:force_aspect_ratio] ? "\\!" : "\\>"}
|
|
||||||
#{to}
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.resize(from, to, width, height, opts={})
|
def self.resize(from, to, width, height, opts={})
|
||||||
@ -164,7 +159,7 @@ class OptimizedImage < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.convert_with(instructions, to)
|
def self.convert_with(instructions, to)
|
||||||
`convert #{instructions.join(" ")} &> /dev/null`
|
`#{instructions.join(" ")} &> /dev/null`
|
||||||
return false if $?.exitstatus != 0
|
return false if $?.exitstatus != 0
|
||||||
|
|
||||||
ImageOptim.new.optimize_image!(to)
|
ImageOptim.new.optimize_image!(to)
|
||||||
|
@ -65,8 +65,8 @@ class Upload < ActiveRecord::Base
|
|||||||
w = svg["width"].to_i
|
w = svg["width"].to_i
|
||||||
h = svg["height"].to_i
|
h = svg["height"].to_i
|
||||||
else
|
else
|
||||||
# fix orientation first
|
# fix orientation first (but not for GIFs)
|
||||||
fix_image_orientation(file.path)
|
fix_image_orientation(file.path) unless filename =~ /\.GIF$/i
|
||||||
# retrieve image info
|
# retrieve image info
|
||||||
image_info = FastImage.new(file) rescue nil
|
image_info = FastImage.new(file) rescue nil
|
||||||
w, h = *(image_info.try(:size) || [0, 0])
|
w, h = *(image_info.try(:size) || [0, 0])
|
||||||
@ -80,7 +80,7 @@ class Upload < ActiveRecord::Base
|
|||||||
|
|
||||||
# crop images depending on their type
|
# crop images depending on their type
|
||||||
if CROPPED_IMAGE_TYPES.include?(options[:image_type])
|
if CROPPED_IMAGE_TYPES.include?(options[:image_type])
|
||||||
allow_animation = false
|
allow_animation = SiteSetting.allow_animated_thumbnails
|
||||||
max_pixel_ratio = Discourse::PIXEL_RATIOS.max
|
max_pixel_ratio = Discourse::PIXEL_RATIOS.max
|
||||||
|
|
||||||
case options[:image_type]
|
case options[:image_type]
|
||||||
|
Loading…
Reference in New Issue
Block a user