-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In RHEL8+ ImageMagick is no longer provided due to being hard to maintain and prone to security issues. That's why we implement an image processor based on the `libgd` backed `local-fastimage_resize` gem for logo processing instead of the Paperclip's default ImageMagick based processor `Paperclip::Thumbnail`. We remove support for uploading GIF profile logos in the process. Logo is used when generating invoices. But prawn only supports JPEGs and PNGs. With ImageMagick we could specify target format for the `:invoice` style to be `png` regardless of source image format. `local-fastimage_resize` only resizes between same formats though. Provided very low adoption of GIF logos, it is not worth implementing such support for `local-fastimage_resize` although it shouldn't be too hard if need arise. Note: existing attachments don't need to be processed because the `:invoice` style will already be PNG. Make sure NOT to manually re-process all attachments though. Anyway no need to. fixes THREESCALE-8579
- Loading branch information
1 parent
89f60bd
commit ee446c2
Showing
14 changed files
with
190 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module Paperclip | ||
class GDImageProcessor < Processor | ||
def make | ||
original_geometry = Geometry.new(*FastImage.size(file)) | ||
computed_geometry = original_geometry.resize_to(target_geometry_str) | ||
file.rewind | ||
original_geometry.to_s[/\d+x\d+/] == computed_geometry.to_s[/\d+x\d+/] ? temp_copy(file) : FastImage.resize(file, computed_geometry.width, computed_geometry.height) | ||
end | ||
|
||
private | ||
|
||
def target_geometry_str | ||
options.fetch(:geometry) | ||
end | ||
|
||
def temp_copy(uploaded_file) | ||
file = Tempfile.new(["copy", File.extname(uploaded_file.path)]) | ||
File.copy_stream(uploaded_file, file) | ||
uploaded_file.rewind | ||
file.rewind | ||
file | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
module Tasks | ||
class FixesTest < ActiveSupport::TestCase | ||
attr_reader :tmpfile | ||
|
||
setup do | ||
@tmpfile = Tempfile.new(%w[logo- .image]) | ||
end | ||
|
||
test 'regenerate JPEG logos :invoice style' do | ||
profile = FactoryBot.create(:profile) | ||
profile.logo.post_processing = false | ||
file_fixture("hypnotoad.jpg").open("rb") { |io| profile.logo = io } | ||
profile.save! | ||
|
||
assert_raises(Errno::ENOENT) { profile.logo.copy_to_local_file :invoice, tmpfile.path } | ||
|
||
execute_rake_task 'fixes.rake', 'fixes:regenerate_jpeg_invoice_logo' | ||
profile.logo.copy_to_local_file :invoice, tmpfile.path | ||
end | ||
|
||
test "regenerate JPEG logos ignores pngs" do | ||
profile = FactoryBot.create(:profile) | ||
profile.logo.post_processing = false | ||
file_fixture("small.png").open("rb") { |io| profile.logo = io } | ||
profile.save! | ||
|
||
execute_rake_task 'fixes.rake', 'fixes:regenerate_jpeg_invoice_logo' | ||
assert_raises(Errno::ENOENT) { profile.logo.copy_to_local_file :invoice, tmpfile.path } | ||
end | ||
|
||
test "regenerate JPEG logos ignores gifs" do | ||
profile = FactoryBot.create(:profile) | ||
profile.logo.post_processing = false | ||
file_fixture("hypnotoad.jpg").open("rb") { |io| profile.logo = io } | ||
profile.save! | ||
profile.update_column(:logo_content_type, "image/gif") | ||
|
||
execute_rake_task 'fixes.rake', 'fixes:regenerate_jpeg_invoice_logo' | ||
assert_raises(Errno::ENOENT) { profile.logo.copy_to_local_file :invoice, tmpfile.path } | ||
end | ||
|
||
test "report JPEG logos fix errors" do | ||
FactoryBot.create(:profile, logo_file_name: "fake.jpg", logo_content_type: "image/jpeg") | ||
Rails.logger.expects(:error).with { |val| val =~ /^Failed to reprocess invoice logo for.*/ } | ||
execute_rake_task 'fixes.rake', 'fixes:regenerate_jpeg_invoice_logo' | ||
end | ||
end | ||
end |