kodhe / image
Kodhe image library
1.1.0
2026-09-28 21:41 UTC
Requires
- php: >=8.1
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is not auto-updated.
Last update: 2026-09-29 21:38:38 UTC
README
Refactored CodeIgniter 3 Image Library with PSR-4/PSR-12 compliance, maintaining full backward compatibility.
Features
- Modular Architecture: Separated into Contracts, Drivers, Operations, Factory, Support, and ValueObjects
- Design Patterns: Strategy, Factory, Command, Value Object, Dependency Injection
- Performance Optimizations: Metadata caching, lazy loading, resource reuse
- PSR-4 Autoloading: Fully compliant with PSR-4 namespace standards
- PSR-12 Coding Style: Follows modern PHP coding standards
- PHPUnit Ready: Testable architecture with dependency injection
Structure
src/
├── ImageLib.php # Main CI3-compatible class
├── Contracts/
│ └── ImageDriverInterface.php
├── Drivers/
│ └── GdDriver.php # GD library driver
├── Factory/
│ └── DriverFactory.php
├── Support/
│ └── ImageMetadataCache.php
└── ValueObjects/
├── ImageDimensions.php
└── ImageInfo.php
Installation
composer require kodhe/image
Usage
Basic Usage (CI3 Compatible)
use Kodhe\Image\ImageLib; $config = [ 'image_library' => 'gd2', 'source_image' => '/path/to/image.jpg', 'new_image' => '/path/to/thumb.jpg', 'width' => 200, 'height' => 200, ]; $image = new ImageLib($config); // Resize if (!$image->resize()) { echo $image->display_errors(); } // Crop $image->clear(); $image->initialize([ 'source_image' => '/path/to/image.jpg', 'x_axis' => 50, 'y_axis' => 50, 'width' => 100, 'height' => 100, ]); $image->crop(); // Rotate $image->clear(); $image->initialize([ 'source_image' => '/path/to/image.jpg', 'rotation_angle' => 90, ]); $image->rotate(); // Watermark $image->clear(); $image->initialize([ 'source_image' => '/path/to/image.jpg', 'wm_type' => 'text', 'wm_text' => 'Copyright 2024', 'wm_font_size' => 16, 'wm_vrt_alignment'=> 'B', 'wm_hor_alignment'=> 'C', ]); $image->watermark(); // Flip $image->clear(); $image->initialize([ 'source_image' => '/path/to/image.jpg', ]); $image->flip('horizontal'); // or 'vertical'
API Methods
All original CI3 Image_lib methods are preserved:
initialize(array $config)- Initialize with configurationresize()- Resize imagecrop()- Crop imagerotate()- Rotate imagewatermark()- Add watermarkflip(string $direction)- Flip/mirror imageclear()- Clear resources and reset statedisplay_errors(string $open, string $close)- Get formatted error messages
Design Patterns Used
Strategy Pattern
Different image processing drivers (GD, ImageMagick) implement the same interface.
Factory Pattern
DriverFactory creates appropriate driver instances based on configuration.
Value Object Pattern
Immutable value objects for image dimensions and metadata.
Dependency Injection
Drivers can be injected for easier testing.
Performance Features
- Metadata Caching: Image properties cached to avoid repeated
getimagesize()calls - Lazy Loading: Drivers loaded only when needed
- Resource Reuse: GD/Imagick resources reused where possible
Testing
composer install vendor/bin/phpunit tests/
License
MIT License