@@ -26,7 +26,7 @@ type ImageProps = Omit<
26
26
'src' | 'srcSet' | 'ref' | 'width' | 'height' | 'loading'
27
27
> & {
28
28
src : string
29
- quality ?: string
29
+ quality ?: number | string
30
30
priority ?: boolean
31
31
loading ?: LoadingValue
32
32
unoptimized ?: boolean
@@ -104,8 +104,8 @@ function getDeviceSizes(width: number | undefined): number[] {
104
104
function computeSrc (
105
105
src : string ,
106
106
unoptimized : boolean ,
107
- width : number | undefined ,
108
- quality ?: string
107
+ width ? : number ,
108
+ quality ?: number
109
109
) : string {
110
110
if ( unoptimized ) {
111
111
return src
@@ -118,7 +118,7 @@ function computeSrc(
118
118
type CallLoaderProps = {
119
119
src : string
120
120
width : number
121
- quality ?: string
121
+ quality ?: number
122
122
}
123
123
124
124
function callLoader ( loaderProps : CallLoaderProps ) {
@@ -129,8 +129,8 @@ function callLoader(loaderProps: CallLoaderProps) {
129
129
type SrcSetData = {
130
130
src : string
131
131
unoptimized : boolean
132
- width : number | undefined
133
- quality : string | undefined
132
+ width ? : number
133
+ quality ?: number
134
134
}
135
135
136
136
function generateSrcSet ( {
@@ -155,7 +155,7 @@ type PreloadData = {
155
155
unoptimized : boolean
156
156
width : number | undefined
157
157
sizes ?: string
158
- quality ?: string
158
+ quality ?: number
159
159
}
160
160
161
161
function generatePreload ( {
@@ -251,8 +251,10 @@ export default function Image({
251
251
}
252
252
} , [ thisEl , lazy ] )
253
253
254
- let widthInt = getInt ( width )
255
- let heightInt = getInt ( height )
254
+ const widthInt = getInt ( width )
255
+ const heightInt = getInt ( height )
256
+ const qualityInt = getInt ( quality )
257
+
256
258
let divStyle : React . CSSProperties | undefined
257
259
let imgStyle : React . CSSProperties | undefined
258
260
let wrapperStyle : React . CSSProperties | undefined
@@ -305,12 +307,12 @@ export default function Image({
305
307
}
306
308
307
309
// Generate attribute values
308
- const imgSrc = computeSrc ( src , unoptimized , widthInt , quality )
310
+ const imgSrc = computeSrc ( src , unoptimized , widthInt , qualityInt )
309
311
const imgSrcSet = generateSrcSet ( {
310
312
src,
311
313
width : widthInt ,
312
314
unoptimized,
313
- quality,
315
+ quality : qualityInt ,
314
316
} )
315
317
316
318
let imgAttributes :
@@ -352,7 +354,7 @@ export default function Image({
352
354
width : widthInt ,
353
355
unoptimized,
354
356
sizes,
355
- quality,
357
+ quality : qualityInt ,
356
358
} )
357
359
: '' }
358
360
< img
@@ -442,7 +444,5 @@ function defaultLoader({ root, src, width, quality }: LoaderProps): string {
442
444
}
443
445
}
444
446
445
- return `${ root } ?url=${ encodeURIComponent ( src ) } &w=${ width } &q=${
446
- quality || '100'
447
- } `
447
+ return `${ root } ?url=${ encodeURIComponent ( src ) } &w=${ width } &q=${ quality || 100 } `
448
448
}
0 commit comments