akbansa / image-php-gumlet
PHP helpers for generating Gumlet image URLs and HTML attributes.
Installs: 6
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/akbansa/image-php-gumlet
Requires
- php: ^8.1
Requires (Dev)
- phpunit/phpunit: ^11.0
README
Lightweight PHP helpers for generating Gumlet image URLs, HTML attributes, and responsive srcset definitions. Ship consistent Gumlet parameters across projects by installing this package with Composer.
Installation
composer require akbansa/image-php-gumlet
Quick start
use Gumlet\Image\GumletImage; $gumlet = GumletImage::forDomain('https://assets.gumlet.io'); $baseParams = [ 'format' => 'auto', 'compress' => 'auto', 'quality' => 80, ]; // Quick one-off URL using a plain array of Gumlet params $buildUrl = $gumlet->buildUrl('pictures/hero.jpg', array_merge($baseParams, [ 'w' => 1200, ])); $img = $gumlet->image('pictures/hero.jpg', $baseParams); echo '<img ' . $img->toHtml([ 'alt' => 'Hero', 'class' => 'hero', ]) . ' />'; // Responsive srcset reuses the same base params per width $srcset = $img->srcset([320, 640, 960, 1280]); // Prefer the fluent Transform API? Keep using $gumlet->transform() $transform = $gumlet->transform()->auto(['format', 'compress'])->quality(80); $urlViaTransform = $gumlet->url('pictures/hero.jpg', $transform);
Features
- ✅ PSR-4 Composer package, drop into any PHP 8.1+ app
- ✅ Fluent
Transformobject for Gumlet query parameters - ✅
UrlBuilderthat normalises paths and optionally signs URLs using Gumlet’s MD5stoken - ✅
ImageAttributeshelper to emitsrc,srcset, and HTML attribute arrays/strings - ✅ Zero dependencies
Secure URLs
When your Gumlet source has Secure URLs enabled, add the signing key while creating the facade:
$gumlet = GumletImage::forDomain( 'https://assets.gumlet.io', 'secure-token-from-gumlet-dashboard' ); $url = $gumlet->url('photos/cat.jpg', $gumlet->transform()->width(800)->auto('format')); // -> https://assets.example.gumlet.io/photos/cat.jpg?w=800&s=<md5 signature>
The signature follows Gumlet’s documented format: md5(secret . '/' . path . '?' . query) where the query section is omitted when no parameters exist. See Signed URLs (Gumlet docs) for background.
Examples
See examples/hero.php for a runnable script that prints an <img> tag with responsive attributes.
Contributing
- Clone the repo and run
composer install - Add or update tests under
tests/ - Run
composer test - Open a pull request 🎉
License
MIT © Sample Code