Testing & Contributing
This guide covers both testing the library and contributing to its development.
Testing
Section titled “Testing”The Imagick Image Processor includes two types of tests to ensure reliability and help you understand how to use the library.
Manual Example Scripts
Section titled “Manual Example Scripts”The test/ directory contains example scripts that demonstrate real-world usage. These are great for:
- Learning how to use the library
- Visual verification of results
- Quick manual testing
- Understanding method parameters
Running Example Scripts
Section titled “Running Example Scripts”# Navigate to project rootcd imagick-image-processor
# Run individual examplesphp test/resize.phpphp test/compress.phpphp test/watermark.phpphp test/opacity.phpphp test/webp.phpphp test/resize-compress.phpphp test/resize-watermark-compression.phpExample Output
Section titled “Example Output”Each script processes images from test/images/input/ and saves results to test/images/output/, showing you exactly what the library does.
Automated PHPUnit Tests
Section titled “Automated PHPUnit Tests”The tests/ directory contains comprehensive automated tests using PHPUnit. These tests:
- Validate all methods work correctly
- Test edge cases and error handling
- Ensure compatibility across PHP versions
- Provide code coverage reports
Running Automated Tests
Section titled “Running Automated Tests”# Install dev dependencies (first time only)composer install
# Run all testscomposer test
# Run tests with coverage reportcomposer test:coverageWhat Gets Tested
Section titled “What Gets Tested”The test suite covers:
- ✅ Image resizing with aspect ratio preservation
- ✅ Compression to target file sizes
- ✅ All 9 watermark positions
- ✅ Opacity adjustments and clamping
- ✅ WebP conversion (if supported)
- ✅ Invalid input handling
- ✅ File format validation
Continuous Integration
Section titled “Continuous Integration”Every push and pull request automatically runs tests via GitHub Actions across multiple PHP versions:
- PHP 8.1
- PHP 8.2
- PHP 8.3
You can see test results in the Actions tab of the repository.
Contributing
Section titled “Contributing”We welcome contributions! Here’s how you can help improve the library.
Getting Started
Section titled “Getting Started”-
Fork the repository
Terminal window # Click "Fork" on GitHub, then clone your forkgit clone https://github.com/YOUR-USERNAME/imagick-image-processor.gitcd imagick-image-processor -
Install dependencies
Terminal window composer installcd docs && pnpm install && cd .. -
Create a branch
Terminal window git checkout -b feature/your-feature-name
Development Workflow
Section titled “Development Workflow”1. Make Your Changes
Section titled “1. Make Your Changes”Edit files in the src/ directory:
src/ImageProcessor.php- Main library code
2. Add Tests
Section titled “2. Add Tests”For new features, add tests in tests/ImageProcessorTest.php:
public function testYourNewFeature(): void{ $outputPath = $this->outputDir . '/your-feature.jpg';
$this->processor->yourNewMethod('input.jpg', $outputPath);
$this->assertFileExists($outputPath); // Add more assertions}3. Add Example Script
Section titled “3. Add Example Script”Create a demo script in test/:
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use Kenura\Imagick\ImageProcessor;
$processor = new ImageProcessor();
// Demonstrate your feature$processor->yourNewMethod('input.jpg', 'output.jpg');
echo "✅ Feature demo complete!\n";4. Update Documentation
Section titled “4. Update Documentation”Add documentation in docs/src/content/docs/:
- Guide: Create
guides/your-feature.md - API Reference: Create
reference/your-method.md - Update sidebar: Edit
docs/astro.config.mjs
5. Run Tests
Section titled “5. Run Tests”# Run all testscomposer test
# Test documentation locallycd docspnpm dev# Visit http://localhost:43216. Commit and Push
Section titled “6. Commit and Push”git add .git commit -m "Add: Your feature description"git push origin feature/your-feature-name7. Create Pull Request
Section titled “7. Create Pull Request”- Go to your fork on GitHub
- Click “Pull Request”
- Describe your changes
- Submit!
Contribution Guidelines
Section titled “Contribution Guidelines”Code Style
Section titled “Code Style”- Follow PSR-12 coding standards
- Use meaningful variable names
- Add comments for complex logic
- Keep methods focused and single-purpose
Commit Messages
Section titled “Commit Messages”Use clear, descriptive commit messages:
# Goodgit commit -m "Add: WebP conversion method with quality control"git commit -m "Fix: Aspect ratio calculation for portrait images"git commit -m "Docs: Add watermark positioning guide"
# Avoidgit commit -m "update"git commit -m "fix bug"Documentation
Section titled “Documentation”- Update README.md for new features
- Add detailed guides in
docs/src/content/docs/guides/ - Include code examples
- Update API reference
What to Contribute
Section titled “What to Contribute”We’re looking for:
Features
Section titled “Features”- New image processing methods
- Format support (AVIF, HEIC, etc.)
- Batch processing utilities
- Performance optimizations
Documentation
Section titled “Documentation”- More examples and use cases
- Tutorials for specific scenarios
- Translations
- Video guides
- Additional test cases
- Performance benchmarks
- Browser compatibility tests
Bug Fixes
Section titled “Bug Fixes”- Check Issues
- Fix reported bugs
- Improve error handling
Getting Help
Section titled “Getting Help”Need help contributing?
- 💬 Open a Discussion
- 🐛 Report a Bug
- 💡 Request a Feature
- 📧 Email: kenuragunarathna@gmail.com
Code of Conduct
Section titled “Code of Conduct”Be respectful and constructive. We’re all here to learn and improve the library together.
License
Section titled “License”By contributing, you agree that your contributions will be licensed under the MIT License.
Recognition
Section titled “Recognition”Contributors will be acknowledged in:
- README.md
- Release notes
- Documentation
Thank you for helping make Imagick Image Processor better! 🎉