Skip to content

Commit

Permalink
Merge pull request #2666 from tvdeyen/preserve-transparent-bg
Browse files Browse the repository at this point in the history
Preserve transparent backgrounds for PNGs
  • Loading branch information
tvdeyen authored Dec 29, 2023
2 parents 02f087c + 3438222 commit 8699664
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/models/alchemy/picture_variant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def encoded_image(image, options = {})
end

if options[:flatten]
encoding_options << "-background transparent" if render_format == "png"
encoding_options << "-flatten"
end

Expand Down
1 change: 1 addition & 0 deletions config/initializers/dragonfly.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

# Dragonfly 1.4.0 only allows `quality` as argument to `encode`
Dragonfly::ImageMagick::Processors::Encode::WHITELISTED_ARGS << "flatten"
Dragonfly::ImageMagick::Processors::Encode::WHITELISTED_ARGS << "background"

Rails.application.config.after_initialize do
Dragonfly.app(:alchemy_pictures).add_processor(:crop_resize, Alchemy::Dragonfly::Processors::CropResize.new)
Expand Down
Binary file added spec/fixtures/animated.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion spec/models/alchemy/picture_variant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
it "flattens the image." do
step = subject.steps[0]
expect(step.name).to eq(:encode)
expect(step.arguments).to eq(["png", "-flatten"])
expect(step.arguments).to eq(["png", "-background transparent -flatten"])
end

context "converted to webp" do
Expand Down

0 comments on commit 8699664

Please sign in to comment.