3232 wasm wazero.Runtime
3333 module wazero.CompiledModule
3434 sem * semaphore.Weighted
35+ orienRegex * regexp.Regexp
3536 thumbRegex * regexp.Regexp
3637 counter atomic.Uint64
3738)
@@ -48,6 +49,7 @@ func compile() {
4849 }
4950
5051 sem = semaphore .NewWeighted (6 )
52+ orienRegex = regexp .MustCompile (`Orientation: +(\d)` )
5153 thumbRegex = regexp .MustCompile (`Thumb size: +(\d+) x (\d+)` )
5254}
5355
@@ -78,7 +80,7 @@ func run(ctx context.Context, root fs.FS, args ...string) ([]byte, error) {
7880// The thumbnail will either be a JPEG, or a PNM file in 8-bit P5/P6 format.
7981// For more about PNM, see https://en.wikipedia.org/wiki/Netpbm
8082func GetThumb (ctx context.Context , file string ) ([]byte , error ) {
81- out , err := run (ctx , fileFS (file ), "dcraw" , "-e" , "-c" , fileFSname )
83+ out , err := run (ctx , fileFS (file ), "dcraw" , "-e" , "-e" , "- c" , fileFSname )
8284 if err != nil {
8385 return nil , err
8486 }
@@ -121,6 +123,19 @@ func GetThumbSize(ctx context.Context, file string) (int, error) {
121123 return max , nil
122124}
123125
126+ // GetOrientation returns the EXIF orientation of the RAW file, or 0 if unknown.
127+ func GetOrientation (ctx context.Context , file string ) int {
128+ out , err := run (ctx , fileFS (file ), "dcraw" , "-i" , "-v" , fileFSname )
129+ if err != nil {
130+ return 0
131+ }
132+
133+ if match := orienRegex .FindSubmatch (out ); match != nil {
134+ return int (match [1 ][0 ] - '0' )
135+ }
136+ return 0
137+ }
138+
124139// GetRAWPixels develops an half-resolution, demosaiced, not white balanced
125140// image from the RAW file.
126141func GetRAWPixels (ctx context.Context , file string ) ([]byte , error ) {
0 commit comments