Skip to content

Commit

Permalink
when an image is converted from png to jpg if a background is not spe…
Browse files Browse the repository at this point in the history
…cified, it is automatically set to black.

Took 57 minutes
  • Loading branch information
erikyo committed Apr 9, 2024
1 parent 763225c commit 059a786
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/encodeImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export function encodeImage(

const options = compressOpt;

if (options.options?.background) {
image.flatten({ background: options.options?.background });
}

/**
* The rest of the image formats
* Will apply compression settings if specified in the settings
Expand All @@ -35,13 +39,15 @@ export function encodeImage(
image = image.jpeg({
mozjpeg: true,
quality: compressOpt.quality,
background: "white",
progressive: compressOpt.progressive,
} as sharp.JpegOptions);
break;
case "jpg":
image = image.jpeg({
quality: compressOpt.quality,
progressive: compressOpt.progressive,
});
} as sharp.JpegOptions);
break;
}
}
Expand Down

0 comments on commit 059a786

Please sign in to comment.