Skip to content

Commit c46f732

Browse files
tai2bencevans
authored andcommitted
fix(linux): Use lookup table on determining filetypes
It makes possitle to derive 'jpeg' from '.jpg'.
1 parent eddfede commit c46f732

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

lib/linux/index.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,18 @@ function maxBuffer (screens) {
133133
return total
134134
}
135135

136+
function guessFiletype (filename) {
137+
switch (path.extname(filename)) {
138+
case '.jpg':
139+
case '.jpeg':
140+
return 'jpeg'
141+
case '.png':
142+
return 'png'
143+
}
144+
145+
return 'jpeg'
146+
}
147+
136148
function linuxSnapshot (options = {}) {
137149
return new Promise((resolve, reject) => {
138150
listDisplays().then((screens) => {
@@ -143,8 +155,7 @@ function linuxSnapshot (options = {}) {
143155
encoding: 'buffer',
144156
maxBuffer: maxBuffer(screens)
145157
}
146-
const extension = path.extname(filename) || '.jpeg'
147-
const filetype = extension.substr(1)
158+
const filetype = guessFiletype(filename)
148159

149160
exec(
150161
`import -silent -window root -crop ${screen.crop} -screen ${filetype}:${filename} `,

0 commit comments

Comments
 (0)