Skip to content

Commit 9225744

Browse files
committed
feat: apply white background to transparent PNG > JPG conversion if options.fileType is image/jpeg or image/jpg
1 parent fdf2f4c commit 9225744

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

lib/image-compression.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export default async function compress(file, options, previousProgress = 0) {
4545
incProgress();
4646

4747
// drawFileInCanvas
48-
const [, origCanvas] = await drawFileInCanvas(file);
48+
const [, origCanvas] = await drawFileInCanvas(file, options);
4949

5050
incProgress();
5151

lib/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ declare namespace imageCompression {
2929
function getFilefromDataUrl(dataUrl: string, filename: string, lastModified?: number): Promise<File>;
3030
function loadImage(src: string): Promise<HTMLImageElement>;
3131
function drawImageInCanvas(img: HTMLImageElement, fileType?: string): HTMLCanvasElement;
32-
function drawFileInCanvas(file: File): Promise<[ImageBitmap | HTMLImageElement, HTMLCanvasElement]>;
32+
function drawFileInCanvas(file: File, options?: Options): Promise<[ImageBitmap | HTMLImageElement, HTMLCanvasElement]>;
3333
function canvasToFile(canvas: HTMLCanvasElement, fileType: string, fileName: string, fileLastModified: number, quality?: number): Promise<File>;
3434
function getExifOrientation(file: File): Promise<number>;
3535
}

lib/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ export function isIOS() {
212212
* @param {File | Blob} file
213213
* @returns {Promise<[ImageBitmap | HTMLImageElement, HTMLCanvasElement | OffscreenCanvas]>}
214214
*/
215-
export async function drawFileInCanvas(file) {
215+
export async function drawFileInCanvas(file, options = {}) {
216216
let img;
217217
try {
218218
if (isIOS()) {
@@ -233,7 +233,7 @@ export async function drawFileInCanvas(file) {
233233
throw e2;
234234
}
235235
}
236-
const canvas = drawImageInCanvas(img, file.type);
236+
const canvas = drawImageInCanvas(img, options.fileType || file.type);
237237
return [img, canvas];
238238
}
239239

0 commit comments

Comments
 (0)