Skip to content

Transparency is lost after resizing a PNG with tRNS chunkΒ #2974

@Socolin

Description

@Socolin

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am running the latest version of ImageSharp
  • I have verified if the problem exist in both DEBUG and RELEASE mode
  • I have searched open and closed issues to ensure it has not already been reported

ImageSharp version

3.1.11

Other ImageSharp packages and versions

none

Environment (Operating system, version and so on)

Linux Ubuntu 24.04

.NET Framework version

net9.0

Description

Hello,

We found an image that is losing transparency after resizing it. After digging more into it the only "special" things seems to be there is a png:tRNS chunk on it.

Steps to Reproduce

I cannot share this image, so I tried to recreate the image with the same properties, the problem seems to be the there with the test image, but I'm not an expert about this. (to be transparent, I used Claude to generate this image: https://claude.ai/public/artifacts/8c3ecd97-14dc-4f37-852e-3cdaea076671)

Source image: (2x2 pixels, displayed at 64x64)

Image

Result after resize to 4x4

ImageSharp

When using ImageSharp with the following piece of code, the result does not have any transparency

using var a = Image.Load("test_trns.png");
using var b = a.Clone(x => x.Resize(4, 4));
b.Save("test.imagesharp.png");
Image

ImageMagick

When using image magick convert test_trns_fixed.png -resize 4x4 test.imagemagick.png it's works as expected

Image

Images

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions