More Types, Fixed isImageBlank
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
|
||||
import { PdfFile } from '../../wrappers/PdfFile';
|
||||
import { PDFPageProxy } from "pdfjs-dist/types/src/display/api.js";
|
||||
import { Image } from 'image-js';
|
||||
import { Image, ImageKind } from 'image-js';
|
||||
|
||||
import { getImagesOnPage } from "./getImagesOnPage.js";
|
||||
import { getImagesOnPage, PDFJSImage } from "./getImagesOnPage.js";
|
||||
|
||||
export async function detectEmptyPages(file: PdfFile, whiteThreashold: number): Promise<number[]> {
|
||||
const pdfDoc = await file.pdfJsDocument;
|
||||
@@ -43,8 +43,9 @@ async function areImagesBlank(page: PDFPageProxy, threshold: number): Promise<bo
|
||||
return true;
|
||||
}
|
||||
|
||||
async function isImageBlank(image: string | Uint8Array | ArrayBuffer, threshold: number): Promise<boolean> {
|
||||
var img = await Image.load(image);
|
||||
// TODO: Fix this function
|
||||
async function isImageBlank(image: PDFJSImage, threshold: number): Promise<boolean> {
|
||||
var img = new Image(image.width, image.height, image.data, { kind: "RGB" as ImageKind }); // TODO: Maybe respect image.kind and convert accordingly, needs to be tested with a pdf with alpha-image
|
||||
var grey = img.grey();
|
||||
var mean = grey.getMean();
|
||||
return mean[0] <= threshold;
|
||||
|
||||
Reference in New Issue
Block a user