Fill transparent areas with white in JPEG output (closes #362)
check / check (push) Failing after 57m50s

JPEG has no transparency, and libvips filled transparent areas with
black, so a logo on a transparent background came back on a black
square. The README now says JPEG output is filled with white.

Model: opus-5-5
This commit was merged in pull request #373.
This commit is contained in:
sneak committed 2026-11-19 06:30:17 +00:00
1 parent 3ad266309c
commit c9040dee20
2 files changed
+17 -2

No files matched your search

+13 -2
View File
@@ -808,9 +808,20 @@ func (p *ImageProcessor) encode(
// every setting whose zero value is not what pixa wants. Stripping metadata
// drops EXIF, XMP, IPTC and the ICC profile.
// exportJPEG encodes img as JPEG at quality, without metadata. The settings
// it leaves out are at libvips' defaults.
// exportJPEG encodes img as JPEG at quality, without metadata. JPEG has no
// transparency, so any transparent areas are filled with white; left to
// itself, libvips would fill them with black. govips scales the 8-bit white
// for a 16-bit image. The settings it leaves out are at libvips' defaults.
func exportJPEG(img *vips.ImageRef, quality int) ([]byte, error) {
if img.HasAlpha() {
err := img.Flatten(&vips.Color{
R: math.MaxUint8, G: math.MaxUint8, B: math.MaxUint8,
})
if err != nil {
return nil, fmt.Errorf("failed to fill transparent areas: %w", err)
}
}
output, _, err := img.ExportJpeg(&vips.JpegExportParams{
StripMetadata: true,
Quality: quality,