54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
// Script to generate test images for each supported format
|
|
import sharp from "sharp";
|
|
|
|
const TEST_DIR = "./test-images";
|
|
|
|
// Ensure test directory exists
|
|
await Deno.mkdir(TEST_DIR, { recursive: true });
|
|
|
|
// Create a simple test image (100x100 red square)
|
|
const testBuffer = await sharp({
|
|
create: {
|
|
width: 100,
|
|
height: 100,
|
|
channels: 3,
|
|
background: { r: 255, g: 0, b: 0 },
|
|
},
|
|
})
|
|
.png()
|
|
.toBuffer();
|
|
|
|
// Save in different formats
|
|
await sharp(testBuffer).toFile(`${TEST_DIR}/test-100x100.png`);
|
|
console.log("Created: test-100x100.png");
|
|
|
|
await sharp(testBuffer).jpeg({ quality: 85 }).toFile(`${TEST_DIR}/test-100x100.jpg`);
|
|
console.log("Created: test-100x100.jpg");
|
|
|
|
await sharp(testBuffer).webp({ quality: 85 }).toFile(`${TEST_DIR}/test-100x100.webp`);
|
|
console.log("Created: test-100x100.webp");
|
|
|
|
// Create a larger test image (200x150 blue rectangle)
|
|
const largeBuffer = await sharp({
|
|
create: {
|
|
width: 200,
|
|
height: 150,
|
|
channels: 3,
|
|
background: { r: 0, g: 0, b: 255 },
|
|
},
|
|
})
|
|
.png()
|
|
.toBuffer();
|
|
|
|
await sharp(largeBuffer).toFile(`${TEST_DIR}/test-200x150.png`);
|
|
console.log("Created: test-200x150.png");
|
|
|
|
await sharp(largeBuffer).jpeg({ quality: 85 }).toFile(`${TEST_DIR}/test-200x150.jpg`);
|
|
console.log("Created: test-200x150.jpg");
|
|
|
|
// Create a GIF test image
|
|
await sharp(largeBuffer).gif().toFile(`${TEST_DIR}/test-200x150.gif`);
|
|
console.log("Created: test-200x150.gif");
|
|
|
|
console.log("\nTest images created successfully!");
|