Skip to content

Commit

Permalink
Exclude webp images from image processing script
Browse files Browse the repository at this point in the history
  • Loading branch information
robinsonzimmermann committed Jan 9, 2025
1 parent b75d8db commit ae5b9ee
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions tools/process-images/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require('fs-extra');
const path = require('path');
const Jimp = require('jimp');
const { GifFrame, GifUtil, GifCodec } = require('gifwrap');
const { GifUtil } = require('gifwrap');

// Get directories and sizes from command line arguments
const sourceDir = path.resolve(process.cwd(), process.argv[2]);
Expand Down Expand Up @@ -32,9 +32,9 @@ const walk = async dir => {
// Exclude 'dist' directories
await walk(fromPath);
}
} else if (/(png|jpg|jpeg|gif)$/i.test(file)) {
} else if (/(png|jpg|jpeg|gif|webp)$/i.test(file)) {
Object.entries(SIZES).forEach(([size, [width, height]]) => {
if (!file.endsWith('.gif')) {
if (!(file.endsWith('.gif') || file.endsWith('.webp'))) {
Jimp.read(fromPath)
.then(img => {
const distDir = path.join(dir, 'dist', size);
Expand All @@ -56,7 +56,7 @@ const walk = async dir => {
.catch(err => {
console.error(err);
});
} else {
} else if (file.endsWith('.gif')) {
GifUtil.read(fromPath).then(gif => {
const distDir = path.join(dir, 'dist', size);
fs.ensureDir(distDir).then(() => {
Expand All @@ -65,6 +65,12 @@ const walk = async dir => {
return GifUtil.write(path.join(distDir, file), gif.frames, gif)
});
});
} else if (file.endsWith('.webp')) {
/**
* TODO: decide on a tool that supports webp
*/
const distDir = path.join(dir, 'dist', size);
fs.ensureDir(distDir).then(() => fs.copy(fromPath, path.join(distDir, file)));
}
});
}
Expand Down

0 comments on commit ae5b9ee

Please sign in to comment.