@dicebear/converter 9.0.1 → 9.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/core.d.ts +3 -1
- package/lib/core.js +6 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/node/core.d.ts +3 -1
- package/lib/node/core.js +12 -5
- package/lib/node/index.d.ts +1 -1
- package/lib/node/index.js +1 -1
- package/lib/types.d.ts +2 -0
- package/lib/utils/mime-type.d.ts +1 -1
- package/lib/utils/mime-type.js +2 -0
- package/package.json +2 -2
package/lib/core.d.ts
CHANGED
package/lib/core.js
CHANGED
|
@@ -6,6 +6,12 @@ export const toPng = (avatar) => {
|
|
|
6
6
|
export const toJpeg = (avatar) => {
|
|
7
7
|
return toFormat(avatar, 'jpeg');
|
|
8
8
|
};
|
|
9
|
+
export const toWebp = (avatar) => {
|
|
10
|
+
return toFormat(avatar, 'webp');
|
|
11
|
+
};
|
|
12
|
+
export const toAvif = (avatar) => {
|
|
13
|
+
return toFormat(avatar, 'avif');
|
|
14
|
+
};
|
|
9
15
|
function toFormat(avatar, format) {
|
|
10
16
|
const svg = typeof avatar === 'string' ? avatar : avatar.toString();
|
|
11
17
|
return {
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
package/lib/node/core.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
import type { ToPng, ToJpeg } from '../types.js';
|
|
1
|
+
import type { ToPng, ToJpeg, ToWebp, ToAvif } from '../types.js';
|
|
2
2
|
export declare const toPng: ToPng;
|
|
3
3
|
export declare const toJpeg: ToJpeg;
|
|
4
|
+
export declare const toWebp: ToWebp;
|
|
5
|
+
export declare const toAvif: ToAvif;
|
package/lib/node/core.js
CHANGED
|
@@ -11,6 +11,12 @@ export const toPng = (avatar, options = {}) => {
|
|
|
11
11
|
export const toJpeg = (avatar, options = {}) => {
|
|
12
12
|
return toFormat(avatar, 'jpeg', options);
|
|
13
13
|
};
|
|
14
|
+
export const toWebp = (avatar, options = {}) => {
|
|
15
|
+
return toFormat(avatar, 'webp', options);
|
|
16
|
+
};
|
|
17
|
+
export const toAvif = (avatar, options = {}) => {
|
|
18
|
+
return toFormat(avatar, 'avif', options);
|
|
19
|
+
};
|
|
14
20
|
function toFormat(avatar, format, options) {
|
|
15
21
|
var _a;
|
|
16
22
|
const svg = typeof avatar === 'string' ? avatar : avatar.toString();
|
|
@@ -40,11 +46,12 @@ async function toBuffer(rawSvg, format, exif, options) {
|
|
|
40
46
|
fontFiles: hasFonts ? options.fonts : undefined,
|
|
41
47
|
},
|
|
42
48
|
})).asPng();
|
|
43
|
-
if ('
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
.
|
|
47
|
-
|
|
49
|
+
if (format !== 'png') {
|
|
50
|
+
const sharpInstance = sharp(buffer);
|
|
51
|
+
if (format === 'jpeg') {
|
|
52
|
+
sharpInstance.flatten({ background: '#ffffff' });
|
|
53
|
+
}
|
|
54
|
+
buffer = await sharpInstance.toFormat(format).toBuffer();
|
|
48
55
|
}
|
|
49
56
|
if (Object.keys(exif).length > 0) {
|
|
50
57
|
buffer = await tmp.withFile(async ({ path }) => {
|
package/lib/node/index.d.ts
CHANGED
package/lib/node/index.js
CHANGED
package/lib/types.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export type ToJpeg = (avatar: Avatar, options?: Options) => Result;
|
|
2
2
|
export type ToPng = (avatar: Avatar, options?: Options) => Result;
|
|
3
|
+
export type ToWebp = (avatar: Avatar, options?: Options) => Result;
|
|
4
|
+
export type ToAvif = (avatar: Avatar, options?: Options) => Result;
|
|
3
5
|
export type Avatar = {
|
|
4
6
|
toString(): string;
|
|
5
7
|
} | string;
|
package/lib/utils/mime-type.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getMimeType(format: 'svg' | 'png' | 'jpeg'): string;
|
|
1
|
+
export declare function getMimeType(format: 'svg' | 'png' | 'jpeg' | 'webp' | 'avif'): string;
|
package/lib/utils/mime-type.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dicebear/converter",
|
|
3
|
-
"version": "9.0
|
|
3
|
+
"version": "9.2.0",
|
|
4
4
|
"description": "SVG Converter for DiceBear",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dicebear"
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"publishConfig": {
|
|
55
55
|
"access": "public"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "a4f64b6235f77e30ca962199d806069c188fcaa7"
|
|
58
58
|
}
|