Main Features
Init Image Processor provides a complete set of professional-grade features for websites that require maximum performance:
- 100% self-hosted: No third-party services. All processing happens on your own server.
- Smart resizing: Automatically preserves aspect ratio when only width or height is provided.
- Allowed Sizes: Restricts resizing to predefined dimensions to prevent cache pollution or parameter-spam attacks.
- Flexible fit modes:
cover,contain, andfillfor precise layout control. - Accurate cropping: Perfectly crop images when combined with fit + crop options.
- WebP & AVIF conversion: Reduce file size dramatically (if GD supports these formats).
- Automatic watermarking: PNG watermark with intelligent scaling and corner placement.
- Powerful caching system:
- File-based caching
- HTTP caching:
ETag,Cache-Control,Expires - Atomic Write: prevents cache corruption during high-traffic parallel requests
- Garbage Collection: automatic cleanup of old cache files via lottery or cronjob
- Advanced security:
- Domain-restricted remote fetching (prevents SSRF)
- MIME validation (prevents disguised script uploads)
- Pixel-limit safeguard to avoid RAM exhaustion
- Sanitized paths to block directory traversal
- No external dependencies: Works with PHP + GD alone—compatible with almost any shared hosting environment.
Version Information
- Version: 1.0.2
- Last Updated: 2026-02-03
System Requirements
For best performance, your server should meet the following requirements:
- PHP: 7.4 or higher (PHP 8+ recommended)
- Extensions:
gd,fileinfo(cURL recommended for better reliability) - Cache directory: writable
/cachefolder (permissions 755 or 775) - HTTPS fetching: enable
INIT_IMG_SSL_VERIFY
Installation & Configuration
Download init-image-processor.php and place it anywhere on your server. Then adjust the configuration section inside the file:
define('INIT_IMG_SOURCE_DOMAIN', 'https://example.com');
define('INIT_IMG_CACHE_DIR', __DIR__ . '/cache');
define('INIT_IMG_ALLOW_REMOTE', true);
define('INIT_IMG_SSL_VERIFY', true);
// Advanced options:
define('INIT_IMG_ALLOWED_WIDTHS', [320, 480, 800, 1024, 1920]);
define('INIT_IMG_MAX_PIXELS', 30 * 1024 * 1024);
define('INIT_IMG_CACHE_GC_PROBABILITY', 1000); // run GC on 1 out of every 1000 requests
define('INIT_IMG_MEMORY_LIMIT', '256M');
INIT_IMG_SOURCE_DOMAIN: Restricts allowed image sources for SSRF protection.INIT_IMG_CACHE_DIR: Directory for storing processed cached images.INIT_IMG_ALLOWED_WIDTHS: Prevents uncontrolled cache growth.INIT_IMG_MAX_PIXELS: Blocks extremely large images from consuming excessive memory.INIT_IMG_CACHE_GC_PROBABILITY: Enables automatic periodic cache cleanup.INIT_IMG_MEMORY_LIMIT: Optional per-script memory limit.
URL Usage Examples
Common use cases:
- Resize image:
?src=uploads/city.jpg&w=800 - Convert to WebP:
?src=uploads/city.jpg&webp=1&q=85 - Convert to AVIF:
?src=uploads/city.jpg&avif=1 - Crop (cover mode):
?src=uploads/city.jpg&w=1200&h=600&crop=1&fit=cover - Contain mode:
?src=uploads/city.jpg&w=600&h=600&fit=contain - Watermark:
?src=uploads/city.jpg&w=1000&watermark=1
How It Works
The processing workflow follows these steps:
- Receive an image path or URL via the
srcparameter. - Validate and authenticate the source domain.
- Fetch the original image via cURL (fallback:
file_get_contents). - Check MIME type and pixel count before loading into GD.
- Process the image according to URL parameters: resize, crop, fit, watermark, convert.
- Save the optimized output into the cache using an atomic write method.
- Return the final image along with proper HTTP cache headers (
ETag,Cache-Control, etc.).
Optimizing with Nginx or Apache
You can expose clean CDN-style URLs using rewrite rules:
location /cdn/img/ {
rewrite ^/cdn/img/(.*)$ /init-image-processor.php?$1 last;
}
Apache example:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^cdn/img/(.*)$ init-image-processor.php?$1 [L,QSA]
</IfModule>
Conclusion
Init Image Processor delivers a powerful, fully self-hosted image optimization workflow designed for modern high-performance websites. With built-in resizing, cropping, format conversion, watermarking, smart caching, and strict security validation, it gives you complete control over how images are processed and served—without relying on any external CDN or cloud service.
Its lightweight architecture makes it easy to integrate into any PHP project, custom framework, or internal CDN setup. By keeping all operations local, it ensures maximum speed, consistent performance, and long-term independence from third-party platforms.
If you’re looking for a fast, secure, and scalable image processing solution that runs entirely on your own server, Init Image Processor is a reliable and future-proof choice within the Init HTML ecosystem.
Install it, apply your rewrite rules, and enjoy CDN-style image optimization directly on your server.
Comments