mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Add compatibility for ImageMagick7.
This commit is contained in:
parent
a7ec949e02
commit
1d74ccaaf8
@ -134,7 +134,7 @@ class OptimizedImage < ActiveRecord::Base
|
|||||||
-background transparent
|
-background transparent
|
||||||
-#{thumbnail_or_resize} #{dimensions}^
|
-#{thumbnail_or_resize} #{dimensions}^
|
||||||
-extent #{dimensions}
|
-extent #{dimensions}
|
||||||
-interpolate bicubic
|
-interpolate catrom
|
||||||
-unsharp 2x0.5+0.7+0
|
-unsharp 2x0.5+0.7+0
|
||||||
-interlace none
|
-interlace none
|
||||||
-quality 98
|
-quality 98
|
||||||
@ -231,12 +231,7 @@ class OptimizedImage < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.convert_with(instructions, to)
|
def self.convert_with(instructions, to)
|
||||||
begin
|
|
||||||
Discourse::Utils.execute_command(*instructions)
|
Discourse::Utils.execute_command(*instructions)
|
||||||
rescue
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
FileHelper.optimize_image!(to)
|
FileHelper.optimize_image!(to)
|
||||||
true
|
true
|
||||||
rescue
|
rescue
|
||||||
|
@ -227,13 +227,13 @@ class UploadCreator
|
|||||||
when "profile_background"
|
when "profile_background"
|
||||||
max_width = 850 * max_pixel_ratio
|
max_width = 850 * max_pixel_ratio
|
||||||
width, height = ImageSizer.resize(@image_info.size[0], @image_info.size[1], max_width: max_width, max_height: max_width)
|
width, height = ImageSizer.resize(@image_info.size[0], @image_info.size[1], max_width: max_width, max_height: max_width)
|
||||||
OptimizedImage.downsize(@file.path, @file.path, "#{width}x#{height}\\>", filename: @filename, allow_animation: allow_animation)
|
OptimizedImage.downsize(@file.path, @file.path, "#{width}x#{height}\>", filename: @filename, allow_animation: allow_animation)
|
||||||
when "card_background"
|
when "card_background"
|
||||||
max_width = 590 * max_pixel_ratio
|
max_width = 590 * max_pixel_ratio
|
||||||
width, height = ImageSizer.resize(@image_info.size[0], @image_info.size[1], max_width: max_width, max_height: max_width)
|
width, height = ImageSizer.resize(@image_info.size[0], @image_info.size[1], max_width: max_width, max_height: max_width)
|
||||||
OptimizedImage.downsize(@file.path, @file.path, "#{width}x#{height}\\>", filename: @filename, allow_animation: allow_animation)
|
OptimizedImage.downsize(@file.path, @file.path, "#{width}x#{height}\>", filename: @filename, allow_animation: allow_animation)
|
||||||
when "custom_emoji"
|
when "custom_emoji"
|
||||||
OptimizedImage.downsize(@file.path, @file.path, "100x100\\>", filename: @filename, allow_animation: allow_animation)
|
OptimizedImage.downsize(@file.path, @file.path, "100x100\>", filename: @filename, allow_animation: allow_animation)
|
||||||
end
|
end
|
||||||
|
|
||||||
extract_image_info!
|
extract_image_info!
|
||||||
|
BIN
spec/fixtures/images/cropped.png
vendored
Normal file
BIN
spec/fixtures/images/cropped.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 113 B |
BIN
spec/fixtures/images/downsized.png
vendored
Normal file
BIN
spec/fixtures/images/downsized.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.3 KiB |
BIN
spec/fixtures/images/resized.png
vendored
Normal file
BIN
spec/fixtures/images/resized.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 199 B |
@ -1,10 +1,71 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe OptimizedImage do
|
describe OptimizedImage do
|
||||||
|
|
||||||
let(:upload) { build(:upload) }
|
let(:upload) { build(:upload) }
|
||||||
before { upload.id = 42 }
|
before { upload.id = 42 }
|
||||||
|
|
||||||
|
describe '.crop' do
|
||||||
|
it 'should work correctly' do
|
||||||
|
tmp_path = "/tmp/cropped.png"
|
||||||
|
|
||||||
|
begin
|
||||||
|
OptimizedImage.crop(
|
||||||
|
"#{Rails.root}/spec/fixtures/images/logo.png",
|
||||||
|
tmp_path,
|
||||||
|
5,
|
||||||
|
5
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(File.read(tmp_path)).to eq(
|
||||||
|
File.read("#{Rails.root}/spec/fixtures/images/cropped.png")
|
||||||
|
)
|
||||||
|
ensure
|
||||||
|
File.delete(tmp_path) if File.exists?(tmp_path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '.resize' do
|
||||||
|
it 'should work correctly' do
|
||||||
|
tmp_path = "/tmp/resized.png"
|
||||||
|
|
||||||
|
begin
|
||||||
|
OptimizedImage.resize(
|
||||||
|
"#{Rails.root}/spec/fixtures/images/logo.png",
|
||||||
|
tmp_path,
|
||||||
|
5,
|
||||||
|
5
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(File.read(tmp_path)).to eq(
|
||||||
|
File.read("#{Rails.root}/spec/fixtures/images/resized.png")
|
||||||
|
)
|
||||||
|
ensure
|
||||||
|
File.delete(tmp_path) if File.exists?(tmp_path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '.downsize' do
|
||||||
|
it 'should work correctly' do
|
||||||
|
tmp_path = "/tmp/downsized.png"
|
||||||
|
|
||||||
|
begin
|
||||||
|
OptimizedImage.downsize(
|
||||||
|
"#{Rails.root}/spec/fixtures/images/logo.png",
|
||||||
|
tmp_path,
|
||||||
|
"100x100\>"
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(File.read(tmp_path)).to eq(
|
||||||
|
File.read("#{Rails.root}/spec/fixtures/images/downsized.png")
|
||||||
|
)
|
||||||
|
ensure
|
||||||
|
File.delete(tmp_path) if File.exists?(tmp_path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe ".safe_path?" do
|
describe ".safe_path?" do
|
||||||
|
|
||||||
it "correctly detects unsafe paths" do
|
it "correctly detects unsafe paths" do
|
||||||
|
Loading…
Reference in New Issue
Block a user