Fill transparent areas with white in JPEG output (closes #362)
check / check (push) In progress
check / check (push) In progress
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 is contained in:
1 parent
3ad266309c
commit
c9040dee20
2 files changed
+17
-2
No files matched your search
@@ -549,6 +549,10 @@ example.
|
||||
PNG or JPEG XL source. This holds in every output format, `orig` included. So an
|
||||
animated GIF requested as GIF comes back as a still GIF.
|
||||
|
||||
**Transparency.** JPEG has no transparency, so pixa fills the transparent areas
|
||||
of an image with white in JPEG output. This applies to `auto` too, when it
|
||||
chooses JPEG.
|
||||
|
||||
**SVG sources.** `orig` of an SVG source is the SVG itself, unchanged, and is
|
||||
cached like any other image. It is given only at the `orig` size, since pixa
|
||||
does not resize an SVG as SVG. `orig` of an SVG at any other size is refused
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user