@@ -166,8 +166,8 @@ export class ImageEngine {
166166
167167 return {
168168 format : input ,
169- width : meta . autoOrient ?. width || meta . width ,
170- height : meta . autoOrient ?. height || meta . height ,
169+ width : meta . autoOrient ?. width ?? meta . width ,
170+ height : meta . autoOrient ?. height ?? meta . height ,
171171 size : ops . data . length ,
172172 space : meta . space ,
173173 channels : meta . channels ,
@@ -198,8 +198,8 @@ function applyFormat(img: sharp.Sharp, ops: ImageOptions): sharp.Sharp {
198198 switch ( ops . format ) {
199199 case ImageType . Avif :
200200 return img . avif ( {
201- quality : ops . quality || preset . quality ,
202- effort : ops . effort || preset . effort ,
201+ quality : ops . quality ?? preset . quality ,
202+ effort : ops . effort ?? preset . effort ,
203203 chromaSubsampling : preset . chromaSubsampling ,
204204 lossless : ops . lossless ,
205205 } ) ;
@@ -208,23 +208,23 @@ function applyFormat(img: sharp.Sharp, ops: ImageOptions): sharp.Sharp {
208208 case ImageType . Heic :
209209 return img . heif ( {
210210 compression : "hevc" ,
211- quality : ops . quality || preset . quality ,
212- effort : ops . effort || preset . effort ,
211+ quality : ops . quality ?? preset . quality ,
212+ effort : ops . effort ?? preset . effort ,
213213 chromaSubsampling : preset . chromaSubsampling ,
214214 lossless : ops . lossless ,
215215 } ) ;
216216 case ImageType . Jpeg :
217217 return img . jpeg ( {
218- quality : ops . quality || preset . quality ,
219- progressive : ops . progressive || preset . progressive ,
218+ quality : ops . quality ?? preset . quality ,
219+ progressive : ops . progressive ?? preset . progressive ,
220220 chromaSubsampling : preset . chromaSubsampling ,
221221 mozjpeg : preset . mozjpeg ,
222222 optimiseCoding : preset . optimiseCoding ,
223223 } ) ;
224224 case ImageType . JpegXL :
225225 return img . jxl ( {
226- quality : ops . quality || preset . quality ,
227- effort : ops . effort || preset . effort ,
226+ quality : ops . quality ?? preset . quality ,
227+ effort : ops . effort ?? preset . effort ,
228228 decodingTier : preset . decodingTier ,
229229 lossless : ops . lossless ,
230230 } ) ;
@@ -245,15 +245,15 @@ function applyFormat(img: sharp.Sharp, ops: ImageOptions): sharp.Sharp {
245245 throw new HttpError ( 400 , "image: encoding type svg is not supported" ) ;
246246 case ImageType . Tiff :
247247 return img . tiff ( {
248- quality : ops . quality || preset . quality ,
248+ quality : ops . quality ?? preset . quality ,
249249 compression : preset . compression ,
250250 predictor : preset . predictor ,
251251 } ) ;
252252 case ImageType . Webp :
253253 return img . webp ( {
254- quality : ops . quality || preset . quality ,
254+ quality : ops . quality ?? preset . quality ,
255255 lossless : ops . lossless ,
256- effort : ops . effort || preset . effort ,
256+ effort : ops . effort ?? preset . effort ,
257257 smartSubsample : preset . smartSubsample ,
258258 smartDeblock : preset . smartDeblock ,
259259 alphaQuality : preset . alphaQuality ,
@@ -316,21 +316,6 @@ export function detectImageFormat(buf: Uint8Array): ImageType {
316316 return ImageType . Tiff ;
317317 }
318318
319- // BMP
320- // if (buf[0] === 0x42 && buf[1] === 0x4d) {
321- // return ImageType.Bmp;
322- // }
323-
324- // ICO
325- // if (buf[0] === 0x00 && buf[1] === 0x00 && buf[2] === 0x01 && buf[3] === 0x00) {
326- // return ImageType.Ico;
327- // }
328-
329- // PSD
330- // if (buf[0] === 0x38 && buf[1] === 0x42 && buf[2] === 0x50 && buf[3] === 0x53) {
331- // return ImageType.Psd;
332- // }
333-
334319 // JPEG XL
335320 if (
336321 ( buf [ 0 ] === 0xff && buf [ 1 ] === 0x0a ) ||
@@ -358,8 +343,6 @@ export function detectImageFormat(buf: Uint8Array): ImageType {
358343 if ( brand . startsWith ( "heic" ) ) return ImageType . Heic ;
359344 if ( brand . startsWith ( "heix" ) ) return ImageType . Heic ;
360345 if ( brand . startsWith ( "hevc" ) ) return ImageType . Heic ;
361- // if (brand.startsWith("heif")) return ImageType.HEIF;
362- // if (brand.startsWith("mif1")) return ImageType.HEIF;
363346 }
364347
365348 // PDF
0 commit comments