-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
65 additions
and
4,818 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
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}`); | ||
} | ||
} | ||
|
||
checkImages(path.join(process.cwd(), 'content')); | ||
checkImages(path.join(process.cwd(), 'static')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.