Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
tdamsma committed Jun 13, 2024
1 parent 51ade09 commit c984596
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 27 deletions.
1 change: 0 additions & 1 deletion .github/workflows/bun.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
name: bun


on:
push:
branches:
Expand Down
52 changes: 26 additions & 26 deletions check-images.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,32 @@ import sharp from 'sharp';
const supportedFormats = ['.jpg', '.jpeg', '.png', '.webp', '.tiff', '.gif', '.svg', '.heif'];

async function checkImages(dir) {
try {
const files = await fs.promises.readdir(dir, { withFileTypes: true });
for (const file of files) {
const filePath = path.join(dir, file.name);
if (file.isDirectory()) {
await checkImages(filePath);
} else if (file.isFile()) {
const ext = path.extname(file.name).toLowerCase();
if (supportedFormats.includes(ext)) {
try {
// Attempt to read the metadata of the image file
await sharp(filePath).metadata();
// Attempt to resize the image
await sharp(filePath)
.resize(100, 100) // Resizing to 100x100 pixels
.toBuffer();
console.log(`Valid image: ${filePath}`);
} catch (error) {
console.error(`Invalid image or unsupported format: ${filePath} - ${error.message}`);
}
}
}
}
} catch (err) {
console.error(`Error reading directory ${dir}: ${err.message}`);
}
try {
const files = await fs.promises.readdir(dir, { withFileTypes: true });
for (const file of files) {
const filePath = path.join(dir, file.name);
if (file.isDirectory()) {
await checkImages(filePath);
} else if (file.isFile()) {
const ext = path.extname(file.name).toLowerCase();
if (supportedFormats.includes(ext)) {
try {
// Attempt to read the metadata of the image file
await sharp(filePath).metadata();
// Attempt to resize the image
await sharp(filePath)
.resize(100, 100) // Resizing to 100x100 pixels
.toBuffer();
console.log(`Valid image: ${filePath}`);
} catch (error) {
console.error(`Invalid image or unsupported format: ${filePath} - ${error.message}`);
}
}
}
}
} catch (err) {
console.error(`Error reading directory ${dir}: ${err.message}`);
}
}

checkImages(path.join(process.cwd(), 'content'));
Expand Down

0 comments on commit c984596

Please sign in to comment.