Initial commit
This commit is contained in:
commit
e49726988c
5445 files changed
+1089914
No files matched your search
+43
@@ -0,0 +1,43 @@
|
||||
import { expect, test, describe } from "vitest";
|
||||
import { createJimp } from "@jimp/core";
|
||||
import { getTestImagePath } from "@jimp/test-utils";
|
||||
|
||||
import jpeg from "./index.js";
|
||||
|
||||
const jimp = createJimp({ formats: [jpeg] });
|
||||
|
||||
describe("JPEG", () => {
|
||||
test("load JPG", async () => {
|
||||
const image = await jimp.read(getTestImagePath("cops.jpg"));
|
||||
|
||||
expect(image.getPixelColor(10, 10)).toBe(0x3f4a02ff);
|
||||
expect(image.getPixelColor(220, 190)).toBe(0x5d94b6ff);
|
||||
expect(image.getPixelColor(350, 130)).toBe(0xdf7944ff);
|
||||
});
|
||||
|
||||
test("load JPG with fill bytes", async () => {
|
||||
const image = await jimp.read(getTestImagePath("fillbytes.jpg"));
|
||||
|
||||
expect(image.getPixelColor(10, 10)).toBe(0xaeb8c3ff);
|
||||
expect(image.getPixelColor(220, 190)).toBe(0x262b21ff);
|
||||
expect(image.getPixelColor(350, 130)).toBe(0x4e5d30ff);
|
||||
});
|
||||
|
||||
test("export JPG", async () => {
|
||||
const image = jimp.fromBitmap({
|
||||
width: 3,
|
||||
height: 3,
|
||||
data: [
|
||||
0xff0000ff, 0xff0080ff, 0xff00ffff, 0xff0080ff, 0xff00ffff, 0x8000ffff,
|
||||
0xff00ffff, 0x8000ffff, 0x0000ffff,
|
||||
],
|
||||
});
|
||||
|
||||
const buffer = await image.getBuffer("image/jpeg", {
|
||||
quality: 50,
|
||||
});
|
||||
|
||||
// eslint-disable-next-line no-control-regex
|
||||
expect(buffer.toString()).toMatch(/^.{3,9}JFIF\u0000/);
|
||||
});
|
||||
});
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
import JPEG from "jpeg-js";
|
||||
import { Format } from "@jimp/types";
|
||||
|
||||
export interface JPEGOptions {
|
||||
quality?: number;
|
||||
}
|
||||
|
||||
export interface DecodeJpegOptions {
|
||||
useTArray?: false;
|
||||
colorTransform?: boolean;
|
||||
formatAsRGBA?: boolean;
|
||||
tolerantDecoding?: boolean;
|
||||
maxResolutionInMP?: number;
|
||||
maxMemoryUsageInMB?: number;
|
||||
}
|
||||
|
||||
export default function jpeg() {
|
||||
return {
|
||||
mime: "image/jpeg",
|
||||
encode: (bitmap, { quality = 100 }: JPEGOptions = {}) =>
|
||||
JPEG.encode(bitmap, quality).data,
|
||||
decode: (data, options?: DecodeJpegOptions) => JPEG.decode(data, options),
|
||||
} satisfies Format<"image/jpeg">;
|
||||
}
|
||||
Reference in new issue
Block a user