Skip to content

Commit 9ed9baa

Browse files
Fix gif directory creation
1 parent dd7e97d commit 9ed9baa

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

tools/process-images/index.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ const walk = async dir => {
3232
// Exclude 'dist' directories
3333
await walk(fromPath);
3434
}
35-
} else if (/(png|jpg|jpeg)$/i.test(file)) {
35+
} else if (/(png|jpg|jpeg|gif)$/i.test(file)) {
3636
Object.entries(SIZES).forEach(([size, [width, height]]) => {
37-
Jimp.read(fromPath)
37+
if (!file.endsWith('.gif')) {
38+
Jimp.read(fromPath)
3839
.then(img => {
3940
const distDir = path.join(dir, 'dist', size);
4041

@@ -55,15 +56,16 @@ const walk = async dir => {
5556
.catch(err => {
5657
console.error(err);
5758
});
58-
});
59-
} else if (/(gif)$/i.test(file)) {
60-
Object.entries(SIZES).forEach(([size, [width, height]]) => {
61-
const distDir = path.join(dir, 'dist', size);
62-
GifUtil.read(fromPath).then(gif => {
63-
gif.width = width;
64-
gif.height = height ?? Math.ceil((width * gif.height) / gif.width);
65-
GifUtil.write(path.join(distDir, file), gif.frames, gif)
66-
});
59+
} else {
60+
GifUtil.read(fromPath).then(gif => {
61+
const distDir = path.join(dir, 'dist', size);
62+
fs.ensureDir(distDir).then(() => {
63+
gif.width = width;
64+
gif.height = height ?? Math.ceil((width * gif.height) / gif.width);
65+
return GifUtil.write(path.join(distDir, file), gif.frames, gif)
66+
});
67+
});
68+
}
6769
});
6870
}
6971
}

0 commit comments

Comments
 (0)