@@ -6,22 +6,28 @@ export async function imageMetadata(
6
6
data : Uint8Array ,
7
7
src ?: string
8
8
) : Promise < Omit < ImageMetadata , 'src' | 'fsPath' > > {
9
- const result = probe ( data ) ;
9
+ try {
10
+ const result = probe ( data ) ;
11
+ if ( ! result . height || ! result . width || ! result . type ) {
12
+ throw new AstroError ( {
13
+ ...AstroErrorData . NoImageMetadata ,
14
+ message : AstroErrorData . NoImageMetadata . message ( src ) ,
15
+ } ) ;
16
+ }
10
17
11
- if ( ! result . height || ! result . width || ! result . type ) {
18
+ const { width, height, type, orientation } = result ;
19
+ const isPortrait = ( orientation || 0 ) >= 5 ;
20
+
21
+ return {
22
+ width : isPortrait ? height : width ,
23
+ height : isPortrait ? width : height ,
24
+ format : type as ImageInputFormat ,
25
+ orientation,
26
+ } ;
27
+ } catch ( e ) {
12
28
throw new AstroError ( {
13
29
...AstroErrorData . NoImageMetadata ,
14
30
message : AstroErrorData . NoImageMetadata . message ( src ) ,
15
31
} ) ;
16
32
}
17
-
18
- const { width, height, type, orientation } = result ;
19
- const isPortrait = ( orientation || 0 ) >= 5 ;
20
-
21
- return {
22
- width : isPortrait ? height : width ,
23
- height : isPortrait ? width : height ,
24
- format : type as ImageInputFormat ,
25
- orientation,
26
- } ;
27
33
}
0 commit comments