Skip to content

Testing & Contributing

This guide covers both testing the library and contributing to its development.

The Imagick Image Processor includes two types of tests to ensure reliability and help you understand how to use the library.

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
Terminal window
# Navigate to project root
cd imagick-image-processor
# Run individual examples
php test/resize.php
php test/compress.php
php test/watermark.php
php test/opacity.php
php test/webp.php
php test/resize-compress.php
php test/resize-watermark-compression.php

Each script processes images from test/images/input/ and saves results to test/images/output/, showing you exactly what the library does.

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
Terminal window
# Install dev dependencies (first time only)
composer install
# Run all tests
composer test
# Run tests with coverage report
composer test:coverage

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

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.

We welcome contributions! Here’s how you can help improve the library.

  1. Fork the repository

    Terminal window
    # Click "Fork" on GitHub, then clone your fork
    git clone https://github.com/YOUR-USERNAME/imagick-image-processor.git
    cd imagick-image-processor
  2. Install dependencies

    Terminal window
    composer install
    cd docs && pnpm install && cd ..
  3. Create a branch

    Terminal window
    git checkout -b feature/your-feature-name

Edit files in the src/ directory:

  • src/ImageProcessor.php - Main library code

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
}

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";

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
Terminal window
# Run all tests
composer test
# Test documentation locally
cd docs
pnpm dev
# Visit http://localhost:4321
Terminal window
git add .
git commit -m "Add: Your feature description"
git push origin feature/your-feature-name
  1. Go to your fork on GitHub
  2. Click “Pull Request”
  3. Describe your changes
  4. Submit!
  • Follow PSR-12 coding standards
  • Use meaningful variable names
  • Add comments for complex logic
  • Keep methods focused and single-purpose

Use clear, descriptive commit messages:

Terminal window
# Good
git 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"
# Avoid
git commit -m "update"
git commit -m "fix bug"
  • Update README.md for new features
  • Add detailed guides in docs/src/content/docs/guides/
  • Include code examples
  • Update API reference

We’re looking for:

  • New image processing methods
  • Format support (AVIF, HEIC, etc.)
  • Batch processing utilities
  • Performance optimizations
  • More examples and use cases
  • Tutorials for specific scenarios
  • Translations
  • Video guides
  • Additional test cases
  • Performance benchmarks
  • Browser compatibility tests
  • Check Issues
  • Fix reported bugs
  • Improve error handling

Need help contributing?

Be respectful and constructive. We’re all here to learn and improve the library together.

By contributing, you agree that your contributions will be licensed under the MIT License.

Contributors will be acknowledged in:

  • README.md
  • Release notes
  • Documentation

Thank you for helping make Imagick Image Processor better! 🎉