UNPKG

contaigents

Version:

Modular AI Content Ecosystem with Audio Generation

167 lines (166 loc) • 6.52 kB
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);