A platform for community discussion. Free, open, simple.
Add compatibility for ImageMagick7.
Guo Xiang Tan1d74ccaaf8cb
diff --git a/app/models/optimized_image.rb b/app/models/optimized_image.rbindex d25f40e30dc..e94d568afc9 100644--- a/app/models/optimized_image.rb+++ b/app/models/optimized_image.rb@@ -134,7 +134,7 @@ class OptimizedImage < ActiveRecord::Base-background transparent-#{thumbnail_or_resize} #{dimensions}^-extent #{dimensions}- -interpolate bicubic+ -interpolate catrom-unsharp 2x0.5+0.7+0-interlace none-quality 98@@ -231,12 +231,7 @@ class OptimizedImage < ActiveRecord::Baseenddef self.convert_with(instructions, to)- begin- Discourse::Utils.execute_command(*instructions)- rescue- return false- end-+ Discourse::Utils.execute_command(*instructions)FileHelper.optimize_image!(to)truerescuediff --git a/lib/upload_creator.rb b/lib/upload_creator.rbindex badc89a6f2a..85f8ca242d7 100644--- a/lib/upload_creator.rb+++ b/lib/upload_creator.rb@@ -227,13 +227,13 @@ class UploadCreatorwhen "profile_background"max_width = 850 * max_pixel_ratiowidth, 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"max_width = 590 * max_pixel_ratiowidth, 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"- 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)endextract_image_info!diff --git a/spec/fixtures/images/cropped.png b/spec/fixtures/images/cropped.pngnew file mode 100644index 00000000000..ad84dfeb4f8Binary files /dev/null and b/spec/fixtures/images/cropped.png differdiff --git a/spec/fixtures/images/downsized.png b/spec/fixtures/images/downsized.pngnew file mode 100644index 00000000000..9f3bd664e2eBinary files /dev/null and b/spec/fixtures/images/downsized.png differdiff --git a/spec/fixtures/images/resized.png b/spec/fixtures/images/resized.pngnew file mode 100644index 00000000000..2dd153303afBinary files /dev/null and b/spec/fixtures/images/resized.png differdiff --git a/spec/models/optimized_image_spec.rb b/spec/models/optimized_image_spec.rbindex ffd51a0b102..7bd649bf1de 100644--- a/spec/models/optimized_image_spec.rb+++ b/spec/models/optimized_image_spec.rb@@ -1,10 +1,71 @@require 'rails_helper'describe OptimizedImage do-let(:upload) { build(:upload) }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?" doit "correctly detects unsafe paths" do