@dicebear/converter
Advanced tools
Comparing version 9.0.1 to 9.1.0
@@ -7,2 +7,2 @@ /*! | ||
*/ | ||
export { toPng, toJpeg } from './core.js'; | ||
export { toPng, toJpeg, toWebp, toAvif } from './core.js'; |
@@ -7,2 +7,2 @@ /*! | ||
*/ | ||
export { toPng, toJpeg } from './core.js'; | ||
export { toPng, toJpeg, toWebp, toAvif } from './core.js'; |
@@ -1,3 +0,5 @@ | ||
import type { ToJpeg, ToPng } from './types.js'; | ||
import type { ToJpeg, ToPng, ToWebp, ToAvif } from './types.js'; | ||
export declare const toPng: ToPng; | ||
export declare const toJpeg: ToJpeg; | ||
export declare const toWebp: ToWebp; | ||
export declare const toAvif: ToAvif; |
@@ -9,2 +9,8 @@ import { getMimeType } from './utils/mime-type.js'; | ||
}; | ||
export const toWebp = (avatar) => { | ||
return toFormat(avatar, 'webp'); | ||
}; | ||
export const toAvif = (avatar) => { | ||
return toFormat(avatar, 'avif'); | ||
}; | ||
function toFormat(avatar, format) { | ||
@@ -11,0 +17,0 @@ const svg = typeof avatar === 'string' ? avatar : avatar.toString(); |
@@ -7,3 +7,3 @@ /*! | ||
*/ | ||
export { toPng, toJpeg } from './core.js'; | ||
export { toPng, toJpeg, toWebp, toAvif } from './core.js'; | ||
export type * from './types.js'; |
@@ -7,2 +7,2 @@ /*! | ||
*/ | ||
export { toPng, toJpeg } from './core.js'; | ||
export { toPng, toJpeg, toWebp, toAvif } from './core.js'; |
@@ -1,3 +0,5 @@ | ||
import type { ToPng, ToJpeg } from '../types.js'; | ||
import type { ToPng, ToJpeg, ToWebp, ToAvif } from '../types.js'; | ||
export declare const toPng: ToPng; | ||
export declare const toJpeg: ToJpeg; | ||
export declare const toWebp: ToWebp; | ||
export declare const toAvif: ToAvif; |
@@ -14,2 +14,8 @@ import { promises as fs } from 'node:fs'; | ||
}; | ||
export const toWebp = (avatar, options = {}) => { | ||
return toFormat(avatar, 'webp', options); | ||
}; | ||
export const toAvif = (avatar, options = {}) => { | ||
return toFormat(avatar, 'avif', options); | ||
}; | ||
function toFormat(avatar, format, options) { | ||
@@ -44,7 +50,8 @@ var _a; | ||
})).asPng(); | ||
if ('jpeg' === format) { | ||
buffer = await sharp(buffer) | ||
.flatten({ background: '#ffffff' }) | ||
.toFormat(format) | ||
.toBuffer(); | ||
if (format !== 'png') { | ||
const sharpInstance = sharp(buffer); | ||
if (format === 'jpeg') { | ||
sharpInstance.flatten({ background: '#ffffff' }); | ||
} | ||
buffer = await sharpInstance.toFormat(format).toBuffer(); | ||
} | ||
@@ -51,0 +58,0 @@ if (Object.keys(exif).length > 0) { |
@@ -7,3 +7,3 @@ /*! | ||
*/ | ||
export { toPng, toJpeg } from './core.js'; | ||
export { toPng, toJpeg, toWebp, toAvif } from './core.js'; | ||
export type * from '../types.js'; |
@@ -7,2 +7,2 @@ /*! | ||
*/ | ||
export { toPng, toJpeg } from './core.js'; | ||
export { toPng, toJpeg, toWebp, toAvif } from './core.js'; |
export type ToJpeg = (avatar: Avatar, options?: Options) => Result; | ||
export type ToPng = (avatar: Avatar, options?: Options) => Result; | ||
export type ToWebp = (avatar: Avatar, options?: Options) => Result; | ||
export type ToAvif = (avatar: Avatar, options?: Options) => Result; | ||
export type Avatar = { | ||
@@ -4,0 +6,0 @@ toString(): string; |
@@ -1,1 +0,1 @@ | ||
export declare function getMimeType(format: 'svg' | 'png' | 'jpeg'): string; | ||
export declare function getMimeType(format: 'svg' | 'png' | 'jpeg' | 'webp' | 'avif'): string; |
@@ -7,2 +7,4 @@ export function getMimeType(format) { | ||
case 'jpeg': | ||
case 'webp': | ||
case 'avif': | ||
return `image/${format}`; | ||
@@ -9,0 +11,0 @@ default: |
{ | ||
"name": "@dicebear/converter", | ||
"version": "9.0.1", | ||
"version": "9.1.0", | ||
"description": "SVG Converter for DiceBear", | ||
@@ -57,3 +57,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "96e800ad4a1f2175f225fe1639fb91624013e01c" | ||
"gitHead": "aa2b97f1679549e4f61dc2e4656794b1be0aee1e" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12999
276