Skip to content

Commit 8a3d74d

Browse files
committed
dev: add bmp support for app icons
1 parent d67a6f0 commit 8a3d74d

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/backend/src/services/AppIconService.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const ICON_SIZES = [16,32,64,128,256,512];
2424
class AppIconService extends BaseService {
2525
static MODULES = {
2626
sharp: require('sharp'),
27+
bmp: require('sharp-bmp'),
2728
}
2829

2930
/**
@@ -80,6 +81,16 @@ class AppIconService extends BaseService {
8081

8182
this.dir_app_icons = dir_app_icons;
8283
}
84+
85+
get_sharp ({ metadata, input }) {
86+
const type = metadata.split(';')[0].split(':')[1];
87+
88+
if ( type === 'image/bmp' ) {
89+
return this.modules.bmp.sharpFromBmp(input);
90+
}
91+
92+
return this.modules.sharp(input);
93+
}
8394

8495
/**
8596
* AppIconService listens to this event to create the
@@ -118,13 +129,18 @@ class AppIconService extends BaseService {
118129
const filename = `${data.app_uid}-${size}.png`;
119130
console.log('FILENAME', filename);
120131
const data_url = data.data_url;
121-
const base64 = data_url.split(',')[1];
132+
const [metadata, base64] = data_url.split(',');
122133
const input = Buffer.from(base64, 'base64');
134+
135+
const sharp_instance = this.get_sharp({
136+
metadata,
137+
input,
138+
});
123139

124140
// NOTE: A stream would be more ideal than a buffer here
125141
// but we have no way of knowing the output size
126142
// before we finish processing the image.
127-
const output = await this.modules.sharp(input)
143+
const output = await sharp_instance
128144
.resize(size)
129145
.png()
130146
.toBuffer();

0 commit comments

Comments
 (0)