PHP code example of rafoabbas / laravel-image-proxy
1. Go to this page and download the library: Download rafoabbas/laravel-image-proxy library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rafoabbas / laravel-image-proxy example snippets
return [
// Filesystem disk to read original images from
'source_disk' => env('IMAGE_PROXY_SOURCE_DISK', 'public'),
// Filesystem disk for storing processed/cached images
'cache_disk' => env('IMAGE_PROXY_CACHE_DISK', 'local'),
// Image processing driver: 'gd' or 'imagick'
'driver' => env('IMAGE_PROXY_DRIVER', 'gd'),
// Output format priority (first match by Accept header wins)
'formats' => ['avif', 'webp'],
// URL signing (HMAC-SHA256)
'signing' => [
'enabled' => env('IMAGE_PROXY_SIGNING_ENABLED', false),
'key' => env('IMAGE_PROXY_SIGNING_KEY'),
],
// Cache remote originals locally
'cache_remote_originals' => true,
// Disks considered remote — originals are cached locally
'remote_disks' => ['s3', 'r2', 'gcs'],
// External domains allowed for URL proxying (empty = disabled)
'allowed_domains' => [],
// Route settings
'route' => [
'enabled' => true,
'path' => 'img',
'middleware' => ['web'],
'name' => 'image-proxy',
],
// Allowed source MIME types
'allowed_mime_types' => [
'image/jpeg',
'image/png',
'image/webp',
'image/gif',
'image/avif',
],
// Dimension and pixel limits
'max_width' => 4000,
'max_height' => 4000,
'max_pixel_count' => 25_000_000,
// Quality settings
'min_quality' => 40,
'max_quality' => 100,
'default_quality' => 85,
// Effects limits
'max_blur' => 50,
// Watermark disk (falls back to source_disk when null)
'watermark_disk' => null,
// Border radius and padding limits
'max_border_radius' => 1000,
'max_padding' => 500,
// Max source file size in bytes (default: 10MB)
'max_file_size' => 10 * 1024 * 1024,
// Cache-Control max-age in seconds (default: 1 year)
'cache_max_age' => 31536000,
];
// Generate a signed URL
ImageProxy::url('photos/secret.jpg', ['w' => 300]);
// => /img/photos/secret.jpg?w=300&s=a1b2c3...
// The signature covers the path and all parameters (tamper-proof)