Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: add alpha premultiplication steps before and after resize #302

Merged
merged 3 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/jekyll_picture_tag/images/image_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,13 @@ def notify
end

def resize(image)
image.resize(scale_value)
if image.has_alpha?
image = image.premultiply
image = image.resize(scale_value)
image.unpremultiply
else
image.resize(scale_value)
end
end

def crop(image)
Expand Down
Binary file added test/image_files/pestka_transparent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions test/unit/images/test_image_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ def test_resize
assert_equal(10, width)
end

def test_resize_with_alpha
restub_source('pestka_transparent', 'png')
tested

width = Vips::Image.new_from_file(filename).width

assert_equal(10, width)
end

def test_quality
# We have to use slightly larger images for the quality to make a difference
# in file size.
Expand Down
Loading