@@ -8,6 +8,13 @@ import {
8
8
type LocalImageService ,
9
9
} from './service.js' ;
10
10
11
+ export interface SharpImageServiceConfig {
12
+ /**
13
+ * The `limitInputPixels` option passed to Sharp. See https://sharp.pixelplumbing.com/api-constructor for more information
14
+ */
15
+ limitInputPixels ?: number ;
16
+ }
17
+
11
18
let sharp : typeof import ( 'sharp' ) ;
12
19
13
20
const qualityTable : Record < ImageQualityPreset , number > = {
@@ -28,13 +35,13 @@ async function loadSharp() {
28
35
return sharpImport ;
29
36
}
30
37
31
- const sharpService : LocalImageService = {
38
+ const sharpService : LocalImageService < SharpImageServiceConfig > = {
32
39
validateOptions : baseService . validateOptions ,
33
40
getURL : baseService . getURL ,
34
41
parseURL : baseService . parseURL ,
35
42
getHTMLAttributes : baseService . getHTMLAttributes ,
36
43
getSrcSet : baseService . getSrcSet ,
37
- async transform ( inputBuffer , transformOptions ) {
44
+ async transform ( inputBuffer , transformOptions , config ) {
38
45
if ( ! sharp ) sharp = await loadSharp ( ) ;
39
46
40
47
const transform : BaseServiceTransform = transformOptions as BaseServiceTransform ;
@@ -43,7 +50,11 @@ const sharpService: LocalImageService = {
43
50
// TODO: Sharp has some support for SVGs, we could probably support this once Sharp is the default and only service.
44
51
if ( transform . format === 'svg' ) return { data : inputBuffer , format : 'svg' } ;
45
52
46
- let result = sharp ( inputBuffer , { failOnError : false , pages : - 1 } ) ;
53
+ const result = sharp ( inputBuffer , {
54
+ failOnError : false ,
55
+ pages : - 1 ,
56
+ limitInputPixels : config . service . config . limitInputPixels ,
57
+ } ) ;
47
58
48
59
// always call rotate to adjust for EXIF data orientation
49
60
result . rotate ( ) ;
0 commit comments