Skip to content

@astrojs/image fails to convert black and transparent png to visible jpg image #4625

@beeb

Description

@beeb

What version of astro are you using?

1.1.5

Are you using an SSR adapter? If so, which one?

None

What package manager are you using?

pnpm

What operating system are you using?

Windows WSL2

Describe the Bug

@astrojs/image version: 0.5.0

When trying to generate an optimized version of a transparent PNG image with black contents (for instance a logo) in a format that doesn't support transparency, the background becomes black and the content becomes invisible.

This is because there is no option to set the background color when the alpha channel is lost due to format conversion.

Link to Minimal Reproducible Example

https://github.com/beeb/astrojs-image-repro

Participation

  • I am willing to submit a pull request for this issue.

Suggestion

Add a background prop to be passed to sharp's flatten method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P2: nice to haveNot breaking anything but nice to have (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions