Initial commit
This commit is contained in:
commit
e49726988c
5445 files changed
+1089914
No files matched your search
+8
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": "../src",
|
||||
"module": "nodenext",
|
||||
"moduleResolution": "nodenext"
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"extends": "./build.json",
|
||||
"include": [
|
||||
"../src/**/*.ts",
|
||||
"../src/**/*.cts",
|
||||
"../src/**/*.tsx",
|
||||
"../src/**/*.json"
|
||||
],
|
||||
"exclude": [
|
||||
"../**/*.test.ts",
|
||||
"../src/**/*.mts",
|
||||
"../src/package.json"
|
||||
],
|
||||
"compilerOptions": {
|
||||
"outDir": "../.tshy-build/commonjs"
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"extends": "./build.json",
|
||||
"include": [
|
||||
"../src/**/*.ts",
|
||||
"../src/**/*.mts",
|
||||
"../src/**/*.tsx",
|
||||
"../src/**/*.json"
|
||||
],
|
||||
"exclude": [
|
||||
"../**/*.test.ts",
|
||||
"../src/package.json"
|
||||
],
|
||||
"compilerOptions": {
|
||||
"outDir": "../.tshy-build/esm"
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
|
||||
|
||||
> @jimp/js-png@1.5.0 build /Users/andrewlisowski/Documents/jimp/plugins/js-png
|
||||
> tshy
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
|
||||
|
||||
> @jimp/js-png@1.1.2 lint /Users/andrewlisowski/Documents/jimp/plugins/js-png
|
||||
> eslint .
|
||||
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
|
||||
|
||||
> @jimp/js-png@1.1.2 test:browser /Users/andrewlisowski/Documents/jimp/plugins/js-png
|
||||
> vitest --config vitest.config.browser.mjs "--watch=false"
|
||||
|
||||
Re-optimizing dependencies because lockfile has changed
|
||||
Port 5173 is in use, trying another one...
|
||||
Port 5174 is in use, trying another one...
|
||||
|
||||
[7m[1m[36m RUN [39m[22m[27m [36mv2.0.5[39m [90m/Users/andrewlisowski/Documents/jimp/plugins/js-png[39m
|
||||
[2m[32m Browser runner started at http://localhost:5175/[39m[22m
|
||||
|
||||
[2m1:39:22 AM[22m [36m[1m[vite][22m[39m [32m✨ new dependencies optimized: [33mvite-plugin-node-polyfills/shims/buffer, vite-plugin-node-polyfills/shims/global, vite-plugin-node-polyfills/shims/process, path[32m[39m
|
||||
[2m1:39:22 AM[22m [36m[1m[vite][22m[39m [32m✨ optimized dependencies changed. reloading[39m
|
||||
[?25l [90m·[39m [2msrc/[22mindex[2m.test.ts[22m[2m (2)[22m
|
||||
[90m·[39m PNG[2m (2)[22m
|
||||
[90m·[39m load PNG
|
||||
[90m·[39m export PNG
|
||||
[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[2K[1A[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (2)[22m
|
||||
[33m❯[39m PNG[2m (2)[22m
|
||||
[33m⠙[39m load PNG
|
||||
[90m·[39m export PNG
|
||||
[?25l[2K[1A[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (2)[22m
|
||||
[33m❯[39m PNG[2m (2)[22m
|
||||
[33m⠹[39m load PNG
|
||||
[90m·[39m export PNG
|
||||
[?25l[2K[1A[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (2)[22m
|
||||
[33m❯[39m PNG[2m (2)[22m
|
||||
[33m⠸[39m load PNG
|
||||
[90m·[39m export PNG
|
||||
[?25l[2K[1A[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (2)[22m
|
||||
[33m❯[39m PNG[2m (2)[22m
|
||||
[33m⠼[39m load PNG
|
||||
[90m·[39m export PNG
|
||||
[?25l[2K[1A[2K[1A[2K[1A[2K[1A[2K[G [33m❯[39m [2msrc/[22mindex[2m.test.ts[22m[2m (2)[22m
|
||||
[33m❯[39m PNG[2m (2)[22m
|
||||
[33m⠴[39m load PNG
|
||||
[90m·[39m export PNG
|
||||
[2K[1A[2K[1A[2K[1A[2K[1A[2K[G [32m✓[39m [2msrc/[22mindex[2m.test.ts[22m[2m (2)[22m
|
||||
[32m✓[39m PNG[2m (2)[22m
|
||||
[32m✓[39m load PNG
|
||||
[32m✓[39m export PNG
|
||||
|
||||
[2m Test Files [22m [1m[32m1 passed[39m[22m[90m (1)[39m
|
||||
[2m Tests [22m [1m[32m2 passed[39m[22m[90m (2)[39m
|
||||
[2m Start at [22m 01:39:13
|
||||
[2m Duration [22m 11.93s[2m (transform 0ms, setup 0ms, collect 560ms, tests 91ms, environment 0ms, prepare 1.57s)[22m
|
||||
|
||||
[?25h[?25h
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
|
||||
|
||||
> @jimp/js-png@1.1.2 test /Users/andrewlisowski/Documents/jimp/plugins/js-png
|
||||
> vitest "--watch=false"
|
||||
|
||||
|
||||
[7m[1m[36m RUN [39m[22m[27m [36mv2.0.5[39m [90m/Users/andrewlisowski/Documents/jimp/plugins/js-png[39m
|
||||
|
||||
[?25l [90m·[39m [2msrc/[22mindex[2m.node.test.ts[22m[2m (1)[22m
|
||||
[?25l[2K[1A[2K[G [32m✓[39m [2msrc/[22mindex[2m.node.test.ts[22m[2m (1)[22m
|
||||
[90m·[39m [2msrc/[22mindex[2m.test.ts[22m[2m (2)[22m
|
||||
[?25l[?25l[?25l[?25l[?25l[?25l[2K[1A[2K[1A[2K[G [32m✓[39m [2msrc/[22mindex[2m.node.test.ts[22m[2m (1)[22m
|
||||
[32m✓[39m [2msrc/[22mindex[2m.test.ts[22m[2m (2)[22m
|
||||
[2K[1A[2K[1A[2K[G [32m✓[39m [2msrc/[22mindex[2m.node.test.ts[22m[2m (1)[22m
|
||||
[32m✓[39m [2msrc/[22mindex[2m.test.ts[22m[2m (2)[22m
|
||||
|
||||
[2m Test Files [22m [1m[32m2 passed[39m[22m[90m (2)[39m
|
||||
[2m Tests [22m [1m[32m3 passed[39m[22m[90m (3)[39m
|
||||
[2m Start at [22m 01:33:35
|
||||
[2m Duration [22m 2.90s[2m (transform 858ms, setup 0ms, collect 1.98s, tests 218ms, environment 1ms, prepare 1.03s)[22m
|
||||
|
||||
[?25h[?25h
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
# v1.5.0 (Sat Sep 07 2024)
|
||||
|
||||
### Release Notes
|
||||
|
||||
#### Add support for image decoder options ([#1336](https://github.com/jimp-dev/jimp/pull/1336))
|
||||
|
||||
Can now have options for the underlying image codecs
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
#### 🚀 Enhancement
|
||||
|
||||
- Add support for image decoder options [#1336](https://github.com/jimp-dev/jimp/pull/1336) ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
||||
|
||||
#### Authors: 1
|
||||
|
||||
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
||||
|
||||
---
|
||||
|
||||
# v1.1.3 (Mon Sep 02 2024)
|
||||
|
||||
#### 🐛 Bug Fix
|
||||
|
||||
- Update deps [#1319](https://github.com/jimp-dev/jimp/pull/1319) ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
||||
|
||||
#### Authors: 1
|
||||
|
||||
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
||||
|
||||
---
|
||||
|
||||
# v1.1.0 (Sun Sep 01 2024)
|
||||
|
||||
#### ⚠️ Pushed to `main`
|
||||
|
||||
- upgrade tshy ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
||||
|
||||
#### Authors: 1
|
||||
|
||||
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
||||
|
||||
---
|
||||
|
||||
# v1.0.3 (Sat Aug 31 2024)
|
||||
|
||||
#### 🐛 Bug Fix
|
||||
|
||||
- Fix build [#1303](https://github.com/jimp-dev/jimp/pull/1303) ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
||||
|
||||
#### ⚠️ Pushed to `main`
|
||||
|
||||
- add clean script ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
||||
|
||||
#### Authors: 1
|
||||
|
||||
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
||||
|
||||
---
|
||||
|
||||
# v1.0.2 (Sat Aug 31 2024)
|
||||
|
||||
#### ⚠️ Pushed to `main`
|
||||
|
||||
- set side effects ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
||||
- fix versions ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
||||
- add publish config ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
||||
|
||||
#### Authors: 1
|
||||
|
||||
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018 Oliver Moran
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
<div align="center">
|
||||
<img width="200" height="200"
|
||||
src="https://s3.amazonaws.com/pix.iemoji.com/images/emoji/apple/ios-11/256/crayon.png">
|
||||
<h1>@jimp/png</h1>
|
||||
<p>Default Jimp png encoder/decoder.</p>
|
||||
</div>
|
||||
|
||||
## Available Methods
|
||||
|
||||
### Jimp.deflateLevel
|
||||
|
||||
Sets the deflate level used when saving as PNG format (default is 9)
|
||||
|
||||
### Jimp.deflateStrategy
|
||||
|
||||
Sets the deflate strategy used when saving as PNG format (default is 3)
|
||||
|
||||
### Jimp.filterType
|
||||
|
||||
Sets the filter type used when saving as PNG format (default is automatic filters)
|
||||
|
||||
### Jimp.colorType
|
||||
|
||||
Sets the color type used when saving as PNG format (one of 0, 2, 4, 6)
|
||||
|
||||
### Filter Types
|
||||
|
||||
```js
|
||||
Jimp.PNG_FILTER_AUTO;
|
||||
Jimp.PNG_FILTER_NONE;
|
||||
Jimp.PNG_FILTER_SUB;
|
||||
Jimp.PNG_FILTER_UP;
|
||||
Jimp.PNG_FILTER_AVERAGE;
|
||||
Jimp.PNG_FILTER_PATH;
|
||||
```
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Filter method is a single-byte integer that indicates the preprocessing method applied to the image data before compression.
|
||||
*/
|
||||
export declare enum PNGFilterType {
|
||||
AUTO = -1,
|
||||
/** scanline is transmitted unmodified */
|
||||
NONE = 0,
|
||||
/** filter transmits the difference between each byte and the value of the corresponding byte of the prior pixel */
|
||||
SUB = 1,
|
||||
/** The Up() filter is just like the Sub() filter except that the pixel immediately above the current pixel, rather than just to its left, is used as the predictor. */
|
||||
UP = 2,
|
||||
/** uses the average of the two neighboring pixels (left and above) to predict the value of a pixel */
|
||||
AVERAGE = 3,
|
||||
/** computes a simple linear function of the three neighboring pixels (left, above, upper left), then chooses as predictor the neighboring pixel closest to the computed value. */
|
||||
PATH = 4
|
||||
}
|
||||
/**
|
||||
* Color type is a single-byte integer that describes the interpretation of the image data.
|
||||
* Color type codes represent sums of the following values:
|
||||
*
|
||||
* 1 (palette used), 2 (color used), and 4 (alpha channel used).
|
||||
*/
|
||||
export declare enum PNGColorType {
|
||||
GRAYSCALE = 0,
|
||||
COLOR = 2,
|
||||
GRAYSCALE_ALPHA = 4,
|
||||
COLOR_ALPHA = 6
|
||||
}
|
||||
//# sourceMappingURL=constants.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,aAAa;IACvB,IAAI,KAAK;IACT,yCAAyC;IACzC,IAAI,IAAI;IACR,mHAAmH;IACnH,GAAG,IAAI;IACP,uKAAuK;IACvK,EAAE,IAAI;IACN,sGAAsG;IACtG,OAAO,IAAI;IACX,kLAAkL;IAClL,IAAI,IAAI;CACT;AAED;;;;;GAKG;AACH,oBAAY,YAAY;IACtB,SAAS,IAAI;IACb,KAAK,IAAI;IACT,eAAe,IAAI;IACnB,WAAW,IAAI;CAChB"}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.PNGColorType = exports.PNGFilterType = void 0;
|
||||
/**
|
||||
* Filter method is a single-byte integer that indicates the preprocessing method applied to the image data before compression.
|
||||
*/
|
||||
var PNGFilterType;
|
||||
(function (PNGFilterType) {
|
||||
PNGFilterType[PNGFilterType["AUTO"] = -1] = "AUTO";
|
||||
/** scanline is transmitted unmodified */
|
||||
PNGFilterType[PNGFilterType["NONE"] = 0] = "NONE";
|
||||
/** filter transmits the difference between each byte and the value of the corresponding byte of the prior pixel */
|
||||
PNGFilterType[PNGFilterType["SUB"] = 1] = "SUB";
|
||||
/** The Up() filter is just like the Sub() filter except that the pixel immediately above the current pixel, rather than just to its left, is used as the predictor. */
|
||||
PNGFilterType[PNGFilterType["UP"] = 2] = "UP";
|
||||
/** uses the average of the two neighboring pixels (left and above) to predict the value of a pixel */
|
||||
PNGFilterType[PNGFilterType["AVERAGE"] = 3] = "AVERAGE";
|
||||
/** computes a simple linear function of the three neighboring pixels (left, above, upper left), then chooses as predictor the neighboring pixel closest to the computed value. */
|
||||
PNGFilterType[PNGFilterType["PATH"] = 4] = "PATH";
|
||||
})(PNGFilterType || (exports.PNGFilterType = PNGFilterType = {}));
|
||||
/**
|
||||
* Color type is a single-byte integer that describes the interpretation of the image data.
|
||||
* Color type codes represent sums of the following values:
|
||||
*
|
||||
* 1 (palette used), 2 (color used), and 4 (alpha channel used).
|
||||
*/
|
||||
var PNGColorType;
|
||||
(function (PNGColorType) {
|
||||
PNGColorType[PNGColorType["GRAYSCALE"] = 0] = "GRAYSCALE";
|
||||
PNGColorType[PNGColorType["COLOR"] = 2] = "COLOR";
|
||||
PNGColorType[PNGColorType["GRAYSCALE_ALPHA"] = 4] = "GRAYSCALE_ALPHA";
|
||||
PNGColorType[PNGColorType["COLOR_ALPHA"] = 6] = "COLOR_ALPHA";
|
||||
})(PNGColorType || (exports.PNGColorType = PNGColorType = {}));
|
||||
//# sourceMappingURL=constants.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,IAAY,aAYX;AAZD,WAAY,aAAa;IACvB,kDAAS,CAAA;IACT,yCAAyC;IACzC,iDAAQ,CAAA;IACR,mHAAmH;IACnH,+CAAO,CAAA;IACP,uKAAuK;IACvK,6CAAM,CAAA;IACN,sGAAsG;IACtG,uDAAW,CAAA;IACX,kLAAkL;IAClL,iDAAQ,CAAA;AACV,CAAC,EAZW,aAAa,6BAAb,aAAa,QAYxB;AAED;;;;;GAKG;AACH,IAAY,YAKX;AALD,WAAY,YAAY;IACtB,yDAAa,CAAA;IACb,iDAAS,CAAA;IACT,qEAAmB,CAAA;IACnB,6DAAe,CAAA;AACjB,CAAC,EALW,YAAY,4BAAZ,YAAY,QAKvB"}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
import { PNGOptions as PNGJSOptions } from "pngjs";
|
||||
import { PNGFilterType, PNGColorType } from "./constants.js";
|
||||
export type { PNGOptions as PNGJSOptions } from "pngjs";
|
||||
export type PNGOptions = Omit<PNGJSOptions, "filterType" | "colorType" | "inputColorType"> & {
|
||||
filterType?: PNGFilterType;
|
||||
colorType?: PNGColorType;
|
||||
inputColorType?: PNGColorType;
|
||||
};
|
||||
export interface DecodePngOptions {
|
||||
checkCRC?: boolean | undefined;
|
||||
skipRescale?: boolean | undefined;
|
||||
}
|
||||
export * from "./constants.js";
|
||||
export default function png(): {
|
||||
mime: "image/png";
|
||||
hasAlpha: true;
|
||||
encode: (bitmap: import("@jimp/types").Bitmap, { deflateLevel, deflateStrategy, filterType, colorType, inputHasAlpha, ...options }?: PNGOptions) => Buffer;
|
||||
decode: (data: Buffer, options?: DecodePngOptions) => {
|
||||
data: Buffer;
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
};
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,UAAU,IAAI,YAAY,EAAE,MAAM,OAAO,CAAC;AAExD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE7D,YAAY,EAAE,UAAU,IAAI,YAAY,EAAE,MAAM,OAAO,CAAC;AACxD,MAAM,MAAM,UAAU,GAAG,IAAI,CAC3B,YAAY,EACZ,YAAY,GAAG,WAAW,GAAG,gBAAgB,CAC9C,GAAG;IACF,UAAU,CAAC,EAAE,aAAa,CAAC;IAC3B,SAAS,CAAC,EAAE,YAAY,CAAC;IACzB,cAAc,CAAC,EAAE,YAAY,CAAC;CAC/B,CAAC;AAEF,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC/B,WAAW,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CACnC;AAED,cAAc,gBAAgB,CAAC;AAE/B,MAAM,CAAC,OAAO,UAAU,GAAG;;;yIAalB,UAAU;qCAuBU,gBAAgB;;;;;EAU5C"}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = png;
|
||||
const pngjs_1 = require("pngjs");
|
||||
const constants_js_1 = require("./constants.js");
|
||||
__exportStar(require("./constants.js"), exports);
|
||||
function png() {
|
||||
return {
|
||||
mime: "image/png",
|
||||
hasAlpha: true,
|
||||
encode: (bitmap, { deflateLevel = 9, deflateStrategy = 3, filterType = constants_js_1.PNGFilterType.AUTO, colorType, inputHasAlpha = true, ...options } = {}) => {
|
||||
const png = new pngjs_1.PNG({
|
||||
width: bitmap.width,
|
||||
height: bitmap.height,
|
||||
});
|
||||
png.data = bitmap.data;
|
||||
return pngjs_1.PNG.sync.write(png, {
|
||||
...options,
|
||||
deflateLevel,
|
||||
deflateStrategy,
|
||||
filterType,
|
||||
colorType: typeof colorType !== "undefined"
|
||||
? colorType
|
||||
: inputHasAlpha
|
||||
? constants_js_1.PNGColorType.COLOR_ALPHA
|
||||
: constants_js_1.PNGColorType.COLOR,
|
||||
inputHasAlpha,
|
||||
});
|
||||
},
|
||||
decode: (data, options) => {
|
||||
const result = pngjs_1.PNG.sync.read(data, options);
|
||||
return {
|
||||
data: result.data,
|
||||
width: result.width,
|
||||
height: result.height,
|
||||
};
|
||||
},
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAqBA,sBA8CC;AAnED,iCAAwD;AAExD,iDAA6D;AAiB7D,iDAA+B;AAE/B,SAAwB,GAAG;IACzB,OAAO;QACL,IAAI,EAAE,WAAW;QACjB,QAAQ,EAAE,IAAI;QACd,MAAM,EAAE,CACN,MAAM,EACN,EACE,YAAY,GAAG,CAAC,EAChB,eAAe,GAAG,CAAC,EACnB,UAAU,GAAG,4BAAa,CAAC,IAAI,EAC/B,SAAS,EACT,aAAa,GAAG,IAAI,EACpB,GAAG,OAAO,KACI,EAAE,EAClB,EAAE;YACF,MAAM,GAAG,GAAG,IAAI,WAAG,CAAC;gBAClB,KAAK,EAAE,MAAM,CAAC,KAAK;gBACnB,MAAM,EAAE,MAAM,CAAC,MAAM;aACtB,CAAC,CAAC;YAEH,GAAG,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;YAEvB,OAAO,WAAG,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE;gBACzB,GAAG,OAAO;gBACV,YAAY;gBACZ,eAAe;gBACf,UAAU;gBACV,SAAS,EACP,OAAO,SAAS,KAAK,WAAW;oBAC9B,CAAC,CAAC,SAAS;oBACX,CAAC,CAAC,aAAa;wBACb,CAAC,CAAC,2BAAY,CAAC,WAAW;wBAC1B,CAAC,CAAC,2BAAY,CAAC,KAAK;gBAC1B,aAAa;aACd,CAAC,CAAC;QACL,CAAC;QACD,MAAM,EAAE,CAAC,IAAI,EAAE,OAA0B,EAAE,EAAE;YAC3C,MAAM,MAAM,GAAG,WAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YAE5C,OAAO;gBACL,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,KAAK,EAAE,MAAM,CAAC,KAAK;gBACnB,MAAM,EAAE,MAAM,CAAC,MAAM;aACtB,CAAC;QACJ,CAAC;KAC4B,CAAC;AAClC,CAAC"}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"type": "commonjs"
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Filter method is a single-byte integer that indicates the preprocessing method applied to the image data before compression.
|
||||
*/
|
||||
export declare enum PNGFilterType {
|
||||
AUTO = -1,
|
||||
/** scanline is transmitted unmodified */
|
||||
NONE = 0,
|
||||
/** filter transmits the difference between each byte and the value of the corresponding byte of the prior pixel */
|
||||
SUB = 1,
|
||||
/** The Up() filter is just like the Sub() filter except that the pixel immediately above the current pixel, rather than just to its left, is used as the predictor. */
|
||||
UP = 2,
|
||||
/** uses the average of the two neighboring pixels (left and above) to predict the value of a pixel */
|
||||
AVERAGE = 3,
|
||||
/** computes a simple linear function of the three neighboring pixels (left, above, upper left), then chooses as predictor the neighboring pixel closest to the computed value. */
|
||||
PATH = 4
|
||||
}
|
||||
/**
|
||||
* Color type is a single-byte integer that describes the interpretation of the image data.
|
||||
* Color type codes represent sums of the following values:
|
||||
*
|
||||
* 1 (palette used), 2 (color used), and 4 (alpha channel used).
|
||||
*/
|
||||
export declare enum PNGColorType {
|
||||
GRAYSCALE = 0,
|
||||
COLOR = 2,
|
||||
GRAYSCALE_ALPHA = 4,
|
||||
COLOR_ALPHA = 6
|
||||
}
|
||||
//# sourceMappingURL=constants.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,aAAa;IACvB,IAAI,KAAK;IACT,yCAAyC;IACzC,IAAI,IAAI;IACR,mHAAmH;IACnH,GAAG,IAAI;IACP,uKAAuK;IACvK,EAAE,IAAI;IACN,sGAAsG;IACtG,OAAO,IAAI;IACX,kLAAkL;IAClL,IAAI,IAAI;CACT;AAED;;;;;GAKG;AACH,oBAAY,YAAY;IACtB,SAAS,IAAI;IACb,KAAK,IAAI;IACT,eAAe,IAAI;IACnB,WAAW,IAAI;CAChB"}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Filter method is a single-byte integer that indicates the preprocessing method applied to the image data before compression.
|
||||
*/
|
||||
export var PNGFilterType;
|
||||
(function (PNGFilterType) {
|
||||
PNGFilterType[PNGFilterType["AUTO"] = -1] = "AUTO";
|
||||
/** scanline is transmitted unmodified */
|
||||
PNGFilterType[PNGFilterType["NONE"] = 0] = "NONE";
|
||||
/** filter transmits the difference between each byte and the value of the corresponding byte of the prior pixel */
|
||||
PNGFilterType[PNGFilterType["SUB"] = 1] = "SUB";
|
||||
/** The Up() filter is just like the Sub() filter except that the pixel immediately above the current pixel, rather than just to its left, is used as the predictor. */
|
||||
PNGFilterType[PNGFilterType["UP"] = 2] = "UP";
|
||||
/** uses the average of the two neighboring pixels (left and above) to predict the value of a pixel */
|
||||
PNGFilterType[PNGFilterType["AVERAGE"] = 3] = "AVERAGE";
|
||||
/** computes a simple linear function of the three neighboring pixels (left, above, upper left), then chooses as predictor the neighboring pixel closest to the computed value. */
|
||||
PNGFilterType[PNGFilterType["PATH"] = 4] = "PATH";
|
||||
})(PNGFilterType || (PNGFilterType = {}));
|
||||
/**
|
||||
* Color type is a single-byte integer that describes the interpretation of the image data.
|
||||
* Color type codes represent sums of the following values:
|
||||
*
|
||||
* 1 (palette used), 2 (color used), and 4 (alpha channel used).
|
||||
*/
|
||||
export var PNGColorType;
|
||||
(function (PNGColorType) {
|
||||
PNGColorType[PNGColorType["GRAYSCALE"] = 0] = "GRAYSCALE";
|
||||
PNGColorType[PNGColorType["COLOR"] = 2] = "COLOR";
|
||||
PNGColorType[PNGColorType["GRAYSCALE_ALPHA"] = 4] = "GRAYSCALE_ALPHA";
|
||||
PNGColorType[PNGColorType["COLOR_ALPHA"] = 6] = "COLOR_ALPHA";
|
||||
})(PNGColorType || (PNGColorType = {}));
|
||||
//# sourceMappingURL=constants.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAN,IAAY,aAYX;AAZD,WAAY,aAAa;IACvB,kDAAS,CAAA;IACT,yCAAyC;IACzC,iDAAQ,CAAA;IACR,mHAAmH;IACnH,+CAAO,CAAA;IACP,uKAAuK;IACvK,6CAAM,CAAA;IACN,sGAAsG;IACtG,uDAAW,CAAA;IACX,kLAAkL;IAClL,iDAAQ,CAAA;AACV,CAAC,EAZW,aAAa,KAAb,aAAa,QAYxB;AAED;;;;;GAKG;AACH,MAAM,CAAN,IAAY,YAKX;AALD,WAAY,YAAY;IACtB,yDAAa,CAAA;IACb,iDAAS,CAAA;IACT,qEAAmB,CAAA;IACnB,6DAAe,CAAA;AACjB,CAAC,EALW,YAAY,KAAZ,YAAY,QAKvB"}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
import { PNGOptions as PNGJSOptions } from "pngjs";
|
||||
import { PNGFilterType, PNGColorType } from "./constants.js";
|
||||
export type { PNGOptions as PNGJSOptions } from "pngjs";
|
||||
export type PNGOptions = Omit<PNGJSOptions, "filterType" | "colorType" | "inputColorType"> & {
|
||||
filterType?: PNGFilterType;
|
||||
colorType?: PNGColorType;
|
||||
inputColorType?: PNGColorType;
|
||||
};
|
||||
export interface DecodePngOptions {
|
||||
checkCRC?: boolean | undefined;
|
||||
skipRescale?: boolean | undefined;
|
||||
}
|
||||
export * from "./constants.js";
|
||||
export default function png(): {
|
||||
mime: "image/png";
|
||||
hasAlpha: true;
|
||||
encode: (bitmap: import("@jimp/types").Bitmap, { deflateLevel, deflateStrategy, filterType, colorType, inputHasAlpha, ...options }?: PNGOptions) => Buffer;
|
||||
decode: (data: Buffer, options?: DecodePngOptions) => {
|
||||
data: Buffer;
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
};
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,UAAU,IAAI,YAAY,EAAE,MAAM,OAAO,CAAC;AAExD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE7D,YAAY,EAAE,UAAU,IAAI,YAAY,EAAE,MAAM,OAAO,CAAC;AACxD,MAAM,MAAM,UAAU,GAAG,IAAI,CAC3B,YAAY,EACZ,YAAY,GAAG,WAAW,GAAG,gBAAgB,CAC9C,GAAG;IACF,UAAU,CAAC,EAAE,aAAa,CAAC;IAC3B,SAAS,CAAC,EAAE,YAAY,CAAC;IACzB,cAAc,CAAC,EAAE,YAAY,CAAC;CAC/B,CAAC;AAEF,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC/B,WAAW,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CACnC;AAED,cAAc,gBAAgB,CAAC;AAE/B,MAAM,CAAC,OAAO,UAAU,GAAG;;;yIAalB,UAAU;qCAuBU,gBAAgB;;;;;EAU5C"}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
import { PNG } from "pngjs";
|
||||
import { PNGFilterType, PNGColorType } from "./constants.js";
|
||||
export * from "./constants.js";
|
||||
export default function png() {
|
||||
return {
|
||||
mime: "image/png",
|
||||
hasAlpha: true,
|
||||
encode: (bitmap, { deflateLevel = 9, deflateStrategy = 3, filterType = PNGFilterType.AUTO, colorType, inputHasAlpha = true, ...options } = {}) => {
|
||||
const png = new PNG({
|
||||
width: bitmap.width,
|
||||
height: bitmap.height,
|
||||
});
|
||||
png.data = bitmap.data;
|
||||
return PNG.sync.write(png, {
|
||||
...options,
|
||||
deflateLevel,
|
||||
deflateStrategy,
|
||||
filterType,
|
||||
colorType: typeof colorType !== "undefined"
|
||||
? colorType
|
||||
: inputHasAlpha
|
||||
? PNGColorType.COLOR_ALPHA
|
||||
: PNGColorType.COLOR,
|
||||
inputHasAlpha,
|
||||
});
|
||||
},
|
||||
decode: (data, options) => {
|
||||
const result = PNG.sync.read(data, options);
|
||||
return {
|
||||
data: result.data,
|
||||
width: result.width,
|
||||
height: result.height,
|
||||
};
|
||||
},
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAA8B,MAAM,OAAO,CAAC;AAExD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAiB7D,cAAc,gBAAgB,CAAC;AAE/B,MAAM,CAAC,OAAO,UAAU,GAAG;IACzB,OAAO;QACL,IAAI,EAAE,WAAW;QACjB,QAAQ,EAAE,IAAI;QACd,MAAM,EAAE,CACN,MAAM,EACN,EACE,YAAY,GAAG,CAAC,EAChB,eAAe,GAAG,CAAC,EACnB,UAAU,GAAG,aAAa,CAAC,IAAI,EAC/B,SAAS,EACT,aAAa,GAAG,IAAI,EACpB,GAAG,OAAO,KACI,EAAE,EAClB,EAAE;YACF,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC;gBAClB,KAAK,EAAE,MAAM,CAAC,KAAK;gBACnB,MAAM,EAAE,MAAM,CAAC,MAAM;aACtB,CAAC,CAAC;YAEH,GAAG,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;YAEvB,OAAO,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE;gBACzB,GAAG,OAAO;gBACV,YAAY;gBACZ,eAAe;gBACf,UAAU;gBACV,SAAS,EACP,OAAO,SAAS,KAAK,WAAW;oBAC9B,CAAC,CAAC,SAAS;oBACX,CAAC,CAAC,aAAa;wBACb,CAAC,CAAC,YAAY,CAAC,WAAW;wBAC1B,CAAC,CAAC,YAAY,CAAC,KAAK;gBAC1B,aAAa;aACd,CAAC,CAAC;QACL,CAAC;QACD,MAAM,EAAE,CAAC,IAAI,EAAE,OAA0B,EAAE,EAAE;YAC3C,MAAM,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YAE5C,OAAO;gBACL,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,KAAK,EAAE,MAAM,CAAC,KAAK;gBACnB,MAAM,EAAE,MAAM,CAAC,MAAM;aACtB,CAAC;QACJ,CAAC;KAC4B,CAAC;AAClC,CAAC"}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"type": "module"
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
import shared from "@jimp/config-eslint/base.js";
|
||||
export default [...shared];
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
{
|
||||
"name": "@jimp/js-png",
|
||||
"version": "1.6.0",
|
||||
"repository": "jimp-dev/jimp",
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "eslint .",
|
||||
"test": "vitest",
|
||||
"test:browser": "vitest --config vitest.config.browser.mjs",
|
||||
"build": "tshy",
|
||||
"dev": "tshy --watch",
|
||||
"clean": "rm -rf node_modules .tshy .tshy-build dist .turbo"
|
||||
},
|
||||
"author": "Andrew Lisowski <lisowski54@gmail.com>",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@jimp/core": "1.6.0",
|
||||
"@jimp/types": "1.6.0",
|
||||
"pngjs": "^7.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@jimp/config-eslint": "1.6.0",
|
||||
"@jimp/config-typescript": "1.6.0",
|
||||
"@jimp/config-vitest": "1.6.0",
|
||||
"@jimp/test-utils": "1.6.0",
|
||||
"@types/pngjs": "^6.0.5",
|
||||
"@vitest/browser": "^2.0.5",
|
||||
"eslint": "^9.9.1",
|
||||
"tshy": "^3.0.2",
|
||||
"typescript": "^5.5.4",
|
||||
"vite-plugin-node-polyfills": "^0.22.0",
|
||||
"vitest": "^2.0.5"
|
||||
},
|
||||
"tshy": {
|
||||
"exclude": [
|
||||
"**/*.test.ts"
|
||||
],
|
||||
"exports": {
|
||||
"./package.json": "./package.json",
|
||||
".": "./src/index.ts"
|
||||
}
|
||||
},
|
||||
"exports": {
|
||||
"./package.json": "./package.json",
|
||||
".": {
|
||||
"import": {
|
||||
"types": "./dist/esm/index.d.ts",
|
||||
"default": "./dist/esm/index.js"
|
||||
},
|
||||
"require": {
|
||||
"types": "./dist/commonjs/index.d.ts",
|
||||
"default": "./dist/commonjs/index.js"
|
||||
}
|
||||
}
|
||||
},
|
||||
"main": "./dist/commonjs/index.js",
|
||||
"types": "./dist/commonjs/index.d.ts",
|
||||
"type": "module",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"module": "./dist/esm/index.js",
|
||||
"gitHead": "c88abe6046dccbdb6e4f5f00c3dd403c81d83515"
|
||||
}
|
||||
Generated
Vendored
BIN
Binary file not shown.
|
After Width: | Height: | Size: 93 B |
+29
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Filter method is a single-byte integer that indicates the preprocessing method applied to the image data before compression.
|
||||
*/
|
||||
export enum PNGFilterType {
|
||||
AUTO = -1,
|
||||
/** scanline is transmitted unmodified */
|
||||
NONE = 0,
|
||||
/** filter transmits the difference between each byte and the value of the corresponding byte of the prior pixel */
|
||||
SUB = 1,
|
||||
/** The Up() filter is just like the Sub() filter except that the pixel immediately above the current pixel, rather than just to its left, is used as the predictor. */
|
||||
UP = 2,
|
||||
/** uses the average of the two neighboring pixels (left and above) to predict the value of a pixel */
|
||||
AVERAGE = 3,
|
||||
/** computes a simple linear function of the three neighboring pixels (left, above, upper left), then chooses as predictor the neighboring pixel closest to the computed value. */
|
||||
PATH = 4,
|
||||
}
|
||||
|
||||
/**
|
||||
* Color type is a single-byte integer that describes the interpretation of the image data.
|
||||
* Color type codes represent sums of the following values:
|
||||
*
|
||||
* 1 (palette used), 2 (color used), and 4 (alpha channel used).
|
||||
*/
|
||||
export enum PNGColorType {
|
||||
GRAYSCALE = 0,
|
||||
COLOR = 2,
|
||||
GRAYSCALE_ALPHA = 4,
|
||||
COLOR_ALPHA = 6,
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
import { expect, test, describe } from "vitest";
|
||||
import "@jimp/test-utils/image-snapshot";
|
||||
import { createJimp } from "@jimp/core";
|
||||
|
||||
import png from "./index.js";
|
||||
|
||||
const jimp = createJimp({ formats: [png] });
|
||||
|
||||
describe("PNG", () => {
|
||||
test("should use png options", async () => {
|
||||
const testImage = jimp.fromBitmap({
|
||||
width: 20,
|
||||
height: 20,
|
||||
data: [
|
||||
0xff0000ff, 0xff0080ff, 0xff00ffff, 0xff0080ff, 0xff00ffff, 0x8000ffff,
|
||||
0xff00ffff, 0x8000ffff, 0x0000ffff, 0xff0000ff, 0xff0080ff, 0xff00ffff,
|
||||
0xff0080ff, 0xff00ffff, 0x8000ffff, 0xff00ffff, 0x8000ffff, 0x0000ffff,
|
||||
0xff0000ff, 0xff0080ff, 0xff00ffff, 0xff0080ff, 0xff00ffff, 0x8000ffff,
|
||||
0xff00ffff, 0x8000ffff, 0x0000ffff, 0xff0000ff, 0xff0080ff, 0xff00ffff,
|
||||
0xff0080ff, 0xff00ffff, 0x8000ffff, 0xff00ffff, 0x8000ffff, 0x0000ffff,
|
||||
],
|
||||
});
|
||||
const image = await testImage.getBuffer("image/png", {
|
||||
deflateStrategy: 0,
|
||||
colorType: 0,
|
||||
});
|
||||
expect(image).toMatchImageSnapshot();
|
||||
});
|
||||
});
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
import { expect, test, describe } from "vitest";
|
||||
import { createJimp } from "@jimp/core";
|
||||
|
||||
import png from "./index.js";
|
||||
import { getTestImagePath } from "@jimp/test-utils";
|
||||
|
||||
const jimp = createJimp({ formats: [png] });
|
||||
|
||||
describe("PNG", () => {
|
||||
test("load PNG", async () => {
|
||||
const image = await jimp.read(getTestImagePath("dice.png"));
|
||||
expect(image.getPixelColor(10, 10)).toBe(0x00000000);
|
||||
expect(image.getPixelColor(160, 80)).toBe(0x1c1cd4ff);
|
||||
expect(image.getPixelColor(400, 250)).toBe(0x7e0c0cda);
|
||||
});
|
||||
|
||||
test("export PNG", async () => {
|
||||
const testImage = jimp.fromBitmap({
|
||||
width: 3,
|
||||
height: 3,
|
||||
data: [
|
||||
0xff0000ff, 0xff0080ff, 0xff00ffff, 0xff0080ff, 0xff00ffff, 0x8000ffff,
|
||||
0xff00ffff, 0x8000ffff, 0x0000ffff,
|
||||
],
|
||||
});
|
||||
const buffer = await testImage.getBuffer("image/png");
|
||||
expect(buffer.toString()).toMatch(/^.PNG\r\n/);
|
||||
});
|
||||
});
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
import { PNG, PNGOptions as PNGJSOptions } from "pngjs";
|
||||
import { Format } from "@jimp/types";
|
||||
import { PNGFilterType, PNGColorType } from "./constants.js";
|
||||
|
||||
export type { PNGOptions as PNGJSOptions } from "pngjs";
|
||||
export type PNGOptions = Omit<
|
||||
PNGJSOptions,
|
||||
"filterType" | "colorType" | "inputColorType"
|
||||
> & {
|
||||
filterType?: PNGFilterType;
|
||||
colorType?: PNGColorType;
|
||||
inputColorType?: PNGColorType;
|
||||
};
|
||||
|
||||
export interface DecodePngOptions {
|
||||
checkCRC?: boolean | undefined;
|
||||
skipRescale?: boolean | undefined;
|
||||
}
|
||||
|
||||
export * from "./constants.js";
|
||||
|
||||
export default function png() {
|
||||
return {
|
||||
mime: "image/png",
|
||||
hasAlpha: true,
|
||||
encode: (
|
||||
bitmap,
|
||||
{
|
||||
deflateLevel = 9,
|
||||
deflateStrategy = 3,
|
||||
filterType = PNGFilterType.AUTO,
|
||||
colorType,
|
||||
inputHasAlpha = true,
|
||||
...options
|
||||
}: PNGOptions = {}
|
||||
) => {
|
||||
const png = new PNG({
|
||||
width: bitmap.width,
|
||||
height: bitmap.height,
|
||||
});
|
||||
|
||||
png.data = bitmap.data;
|
||||
|
||||
return PNG.sync.write(png, {
|
||||
...options,
|
||||
deflateLevel,
|
||||
deflateStrategy,
|
||||
filterType,
|
||||
colorType:
|
||||
typeof colorType !== "undefined"
|
||||
? colorType
|
||||
: inputHasAlpha
|
||||
? PNGColorType.COLOR_ALPHA
|
||||
: PNGColorType.COLOR,
|
||||
inputHasAlpha,
|
||||
});
|
||||
},
|
||||
decode: (data, options?: DecodePngOptions) => {
|
||||
const result = PNG.sync.read(data, options);
|
||||
|
||||
return {
|
||||
data: result.data,
|
||||
width: result.width,
|
||||
height: result.height,
|
||||
};
|
||||
},
|
||||
} satisfies Format<"image/png">;
|
||||
}
|
||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 91 B |
+6
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"extends": "@jimp/config-typescript/base.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist"
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
import config from "@jimp/config-vitest/browser";
|
||||
|
||||
export default config;
|
||||
Reference in new issue
Block a user