@@ -98,13 +98,20 @@ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
9898type Constructor < T > = new ( ...args : any [ ] ) => T ;
9999
100100type JimpFormat <
101- M extends string = string ,
102- O extends Record < string , any > | undefined = undefined ,
103- T extends Format < M , O > = Format < M , O > ,
101+ MimeType extends string = string ,
102+ EncodeOptions extends Record < string , any > | undefined = undefined ,
103+ DecodeOptions extends Record < string , any > | undefined = undefined ,
104+ T extends Format < MimeType , EncodeOptions , DecodeOptions > = Format <
105+ MimeType ,
106+ EncodeOptions ,
107+ DecodeOptions
108+ > ,
104109> = ( ) => T ;
105110
106111type CreateMimeTypeToExportOptions < T extends Format < string , any > > =
107112 T extends Format < infer M , infer O > ? Record < M , O > : never ;
113+ type CreateMimeTypeToDecodeOptions < T extends Format < string , any > > =
114+ T extends Format < infer M , any , infer O > ? Record < M , O > : never ;
108115type GetOptionsForMimeType < Mime extends string , MimeTypeMap > =
109116 MimeTypeMap extends Record < Mime , infer O > ? O : never ;
110117
@@ -138,6 +145,9 @@ export function createJimp<
138145 type MimeTypeToExportOptions = CreateMimeTypeToExportOptions <
139146 ReturnType < Formats [ number ] >
140147 > ;
148+ type MimeTypeToDecodeOptions = CreateMimeTypeToDecodeOptions <
149+ ReturnType < Formats [ number ] >
150+ > ;
141151 type ExtensionToMimeType = CreateExtensionToMimeType < SupportedMimeTypes > ;
142152
143153 const plugins = pluginsArg || [ ] ;
@@ -213,7 +223,10 @@ export function createJimp<
213223 * const image = await Jimp.read("https://upload.wikimedia.org/wikipedia/commons/0/01/Bot-Test.jpg");
214224 * ```
215225 */
216- static async read ( url : string | Buffer | ArrayBuffer ) {
226+ static async read (
227+ url : string | Buffer | ArrayBuffer ,
228+ options ?: MimeTypeToDecodeOptions
229+ ) {
217230 if ( Buffer . isBuffer ( url ) || url instanceof ArrayBuffer ) {
218231 return this . fromBuffer ( url ) ;
219232 }
@@ -239,7 +252,7 @@ export function createJimp<
239252 }
240253
241254 const buffer = bufferFromArrayBuffer ( data ) ;
242- return this . fromBuffer ( buffer ) ;
255+ return this . fromBuffer ( buffer , options ) ;
243256 }
244257
245258 /**
@@ -314,7 +327,10 @@ export function createJimp<
314327 * const image = await Jimp.fromBuffer(buffer);
315328 * ```
316329 */
317- static async fromBuffer ( buffer : Buffer | ArrayBuffer ) {
330+ static async fromBuffer (
331+ buffer : Buffer | ArrayBuffer ,
332+ options ?: MimeTypeToDecodeOptions
333+ ) {
318334 const actualBuffer =
319335 buffer instanceof ArrayBuffer ? bufferFromArrayBuffer ( buffer ) : buffer ;
320336
@@ -331,7 +347,7 @@ export function createJimp<
331347 }
332348
333349 const image = new CustomJimp (
334- await format . decode ( actualBuffer )
350+ await format . decode ( actualBuffer , options ?. [ format . mime ] )
335351 ) as InstanceType < typeof CustomJimp > & ExtraMethodMap ;
336352
337353 image . mime = mime . mime ;
0 commit comments