Skip to content

Commit 29d4559

Browse files
committed
fix: still image jpeg signature
1 parent 9dae0bb commit 29d4559

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

src/lib/still-camera.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ test('takeImage() returns JPEG', async () => {
55

66
const jpegImage = await stillCamera.takeImage();
77

8-
expect(jpegImage.indexOf(StillCamera.jpegSignature)).toBe(0);
8+
expect(jpegImage.indexOf(await StillCamera.getJpegSignature())).toBe(0);
99
});

src/lib/still-camera.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import * as si from 'systeminformation';
2+
import { Flip, Rotation } from '..';
13
import { spawnPromise } from '../util';
2-
import { Rotation, Flip } from '..';
34

45
export interface StillOptions {
56
width?: number;
@@ -10,20 +11,6 @@ export interface StillOptions {
1011
}
1112

1213
export default class StillCamera {
13-
static readonly jpegSignature = Buffer.from([
14-
0xff,
15-
0xd8,
16-
0xff,
17-
0xe1,
18-
0x64,
19-
0x1a,
20-
0x45,
21-
0x78,
22-
0x69,
23-
0x66,
24-
0x00,
25-
]);
26-
2714
private readonly options: StillOptions;
2815

2916
constructor(options: StillOptions = {}) {
@@ -35,6 +22,20 @@ export default class StillCamera {
3522
};
3623
}
3724

25+
static async getJpegSignature() {
26+
const systemInfo = await si.system();
27+
switch (systemInfo.model) {
28+
case 'BCM2835 - Pi 3 Model B':
29+
case 'BCM2835 - Pi 3 Model B+':
30+
case 'BCM2835 - Pi 4 Model B':
31+
return Buffer.from([0xff, 0xd8, 0xff, 0xe1]);
32+
default:
33+
throw new Error(
34+
`Could not determine JPEG signature. Unknown system model '${systemInfo.model}'`,
35+
);
36+
}
37+
}
38+
3839
async takeImage() {
3940
try {
4041
return await spawnPromise('raspistill', [

0 commit comments

Comments
 (0)