contaigents
Version:
Modular AI Content Ecosystem with Audio Generation
167 lines (166 loc) ⢠6.52 kB
JavaScript
import { ImageManipulationTool } from '../services/tools/ImageManipulationTool.js';
import fs from 'fs/promises';
async function testImageManipulation() {
console.log('šØ Testing Image Manipulation Tool');
console.log('==================================\n');
const tool = new ImageManipulationTool(process.cwd());
const testImage = 'demo/test_ref_image.jpeg';
// Check if test image exists
try {
await fs.access(testImage);
console.log(`ā
Test image found: ${testImage}`);
}
catch {
console.log(`ā Test image not found: ${testImage}`);
console.log('Please ensure demo/test_ref_image.jpeg exists');
return;
}
console.log('\nš Test 1: Basic Resize');
try {
const result1 = await tool.execute({
input_path: testImage,
output_path: 'demo/resized_image.jpg',
operations: JSON.stringify([
{ op: 'resize', width: 400, height: 300, fit: 'cover' }
])
});
if (result1.success) {
console.log('ā
Resize successful');
console.log(`š ${result1.data?.processing_summary}`);
console.log(`š Output: ${result1.data?.output_size}, ${result1.data?.file_size}`);
}
else {
console.log(`ā Resize failed: ${result1.error}`);
}
}
catch (error) {
console.log(`ā Resize error: ${error.message}`);
}
console.log('\nš Test 2: Color Adjustments');
try {
const result2 = await tool.execute({
input_path: testImage,
output_path: 'demo/color_adjusted.jpg',
operations: JSON.stringify([
{ op: 'resize', width: 600, height: 400 },
{ op: 'modulate', brightness: 1.2, saturation: 1.3, hue: 15 },
{ op: 'sharpen', sigma: 1.0 }
])
});
if (result2.success) {
console.log('ā
Color adjustment successful');
console.log(`š ${result2.data?.processing_summary}`);
}
else {
console.log(`ā Color adjustment failed: ${result2.error}`);
}
}
catch (error) {
console.log(`ā Color adjustment error: ${error.message}`);
}
console.log('\nš Test 3: Advanced Effects');
try {
const result3 = await tool.execute({
input_path: testImage,
output_path: 'demo/effects_applied.jpg',
operations: JSON.stringify([
{ op: 'resize', width: 500 },
{ op: 'rotate', angle: 10, background: '#ffffff' },
{ op: 'blur', sigma: 2.0 },
{ op: 'linear', a: 1.1, b: 5 }, // Slight brightness/contrast boost
{ op: 'format', type: 'jpeg', quality: 85 }
])
});
if (result3.success) {
console.log('ā
Advanced effects successful');
console.log(`š ${result3.data?.processing_summary}`);
}
else {
console.log(`ā Advanced effects failed: ${result3.error}`);
}
}
catch (error) {
console.log(`ā Advanced effects error: ${error.message}`);
}
console.log('\nš Test 4: Crop and Flip');
try {
const result4 = await tool.execute({
input_path: testImage,
output_path: 'demo/cropped_flipped.png',
operations: JSON.stringify([
{ op: 'crop', left: 50, top: 50, width: 300, height: 300 },
{ op: 'flip' },
{ op: 'modulate', saturation: 0.5 }, // Desaturate
{ op: 'format', type: 'png' }
])
});
if (result4.success) {
console.log('ā
Crop and flip successful');
console.log(`š ${result4.data?.processing_summary}`);
}
else {
console.log(`ā Crop and flip failed: ${result4.error}`);
}
}
catch (error) {
console.log(`ā Crop and flip error: ${error.message}`);
}
console.log('\nš Test 5: Artistic Effects');
try {
const result5 = await tool.execute({
input_path: testImage,
output_path: 'demo/artistic.jpg',
operations: JSON.stringify([
{ op: 'resize', width: 400, height: 400, fit: 'cover' },
{ op: 'gamma', gamma: 1.5 },
{ op: 'modulate', brightness: 0.9, saturation: 1.4, hue: -20 },
{ op: 'sharpen', sigma: 0.8 },
{ op: 'normalize' } // Auto-levels
])
});
if (result5.success) {
console.log('ā
Artistic effects successful');
console.log(`š ${result5.data?.processing_summary}`);
}
else {
console.log(`ā Artistic effects failed: ${result5.error}`);
}
}
catch (error) {
console.log(`ā Artistic effects error: ${error.message}`);
}
// List generated files
console.log('\nš Generated Files:');
const outputFiles = [
'demo/resized_image.jpg',
'demo/color_adjusted.jpg',
'demo/effects_applied.jpg',
'demo/cropped_flipped.png',
'demo/artistic.jpg'
];
for (const file of outputFiles) {
try {
const stats = await fs.stat(file);
console.log(`ā
${file} (${(stats.size / 1024).toFixed(1)} KB)`);
}
catch {
console.log(`ā ${file} (not created)`);
}
}
console.log('\nš Image Manipulation Tests Completed!');
console.log('\nš” What This Tool Can Do:');
console.log(' ā
Resize, crop, rotate, flip images');
console.log(' ā
Adjust brightness, contrast, saturation, hue');
console.log(' ā
Apply filters: sharpen, blur, median');
console.log(' ā
Color effects: gamma, levels, normalize, negate');
console.log(' ā
Format conversion with quality control');
console.log(' ā
Batch operations in single command');
console.log('\nšÆ Agent Usage Examples:');
console.log(' ⢠"Resize image.jpg to 800x600 and increase brightness"');
console.log(' ⢠"Crop photo.png to square and apply vintage effect"');
console.log(' ⢠"Convert screenshot.png to grayscale and sharpen"');
console.log(' ⢠"Rotate artwork.jpg 45 degrees with white background"');
console.log('\nš Ready for Production Use!');
}
// Run the test
testImageManipulation().catch(console.error);