Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@
"@jimp/utils": "workspace:*",
"await-to-js": "^3.0.0",
"exif-parser": "^0.1.12",
"file-type": "^16.0.0",
"file-type": "^21.3.3",
"mime": "3"
},
"devDependencies": {
"@jimp/config-eslint": "workspace:*",
"@jimp/config-typescript": "workspace:*",
"@jimp/test-utils": "workspace:*",
"@types/file-type": "^10.9.1",
"@types/mime": "^3.0.4",
"@types/node": "^18.19.48",
"eslint": "^9.9.1",
Expand Down
12 changes: 10 additions & 2 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Bitmap, Format, JimpClass, Edge } from "@jimp/types";
import { cssColorToHex, scan, scanIterator } from "@jimp/utils";
import fileType from "file-type/core.js";
import { to } from "await-to-js";
import { existsSync, readFile, writeFile } from "@jimp/file-ops";
import mime from "mime/lite.js";
Expand Down Expand Up @@ -29,6 +28,15 @@ function bufferFromArrayBuffer(arrayBuffer: ArrayBuffer) {
return buffer;
}

async function detectFileTypeFromBuffer(buffer: Buffer | ArrayBuffer) {
const { fileTypeFromBuffer } = await import("file-type");
return fileTypeFromBuffer(
buffer instanceof ArrayBuffer
? buffer
: new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength)
);
}

export { getExifOrientation } from "./utils/image-bitmap.js";
export { composite } from "./utils/composite.js";
export * from "./utils/constants.js";
Expand Down Expand Up @@ -334,7 +342,7 @@ export function createJimp<
const actualBuffer =
buffer instanceof ArrayBuffer ? bufferFromArrayBuffer(buffer) : buffer;

const mime = await fileType.fromBuffer(actualBuffer);
const mime = await detectFileTypeFromBuffer(actualBuffer);

if (!mime || !mime.mime) {
throw new Error("Could not find MIME for Buffer");
Expand Down
2 changes: 1 addition & 1 deletion plugins/plugin-quantize/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const methods = {
} = QuantizeOptionsSchema.parse(options);

const inPointContainer = utils.PointContainer.fromUint8Array(
image.bitmap.data,
new Uint8Array(image.bitmap.data.buffer),
image.bitmap.width,
image.bitmap.height
);
Expand Down
4 changes: 2 additions & 2 deletions plugins/wasm-avif/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ export default function avif() {
},
decode: async (data) => {
await initDecoder();
const result = await decode(data);
const result = await decode(new Uint8Array(data).buffer);

return {
data: Buffer.from(result.data),
data: Buffer.from(new Uint8Array(result.data.buffer, result.data.byteOffset, result.data.byteLength)),
width: result.width,
height: result.height,
};
Expand Down
4 changes: 2 additions & 2 deletions plugins/wasm-jpeg/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ export default function jpeg() {
},
decode: async (data) => {
await initDecoder();
const result = await decode(data);
const result = await decode(new Uint8Array(data).buffer);

return {
data: Buffer.from(result.data),
data: Buffer.from(new Uint8Array(result.data.buffer, result.data.byteOffset, result.data.byteLength)),
width: result.width,
height: result.height,
};
Expand Down
4 changes: 2 additions & 2 deletions plugins/wasm-png/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ export default function png() {
},
decode: async (data) => {
await initDecoder();
const result = await decode(data);
const result = await decode(new Uint8Array(data).buffer);

return {
data: Buffer.from(result.data),
data: Buffer.from(new Uint8Array(result.data.buffer, result.data.byteOffset, result.data.byteLength)),
width: result.width,
height: result.height,
};
Expand Down
4 changes: 2 additions & 2 deletions plugins/wasm-webp/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ export default function png() {
},
decode: async (data) => {
await initDecoder();
const result = await decode(data);
const result = await decode(new Uint8Array(data).buffer);

return {
data: Buffer.from(result.data),
data: Buffer.from(new Uint8Array(result.data.buffer, result.data.byteOffset, result.data.byteLength)),
width: result.width,
height: result.height,
};
Expand Down
Loading
Loading