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

v1.2.0 2025-11-19 12:00 UTC

This package is auto-updated.

Last update: 2025-11-19 12:01:31 UTC


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 Transform object for Gumlet query parameters
  • UrlBuilder that normalises paths and optionally signs URLs using Gumlet’s MD5 s token
  • ImageAttributes helper to emit src, 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

  1. Clone the repo and run composer install
  2. Add or update tests under tests/
  3. Run composer test
  4. Open a pull request 🎉

License

MIT © Sample Code