jdz / image
JDZ Image utils
1.1.0
2026-10-11 15:09 UTC
Requires
- php: >=8.2
- ext-gd: *
- imagine/imagine: ^1.3
- symfony/filesystem: ^7.4
- symfony/finder: ^7.4
Requires (Dev)
- phpunit/phpunit: ^11.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
JDZ Image utilities for thumbnail generation, watermark protection, and HTML rendering.
Installation
composer require jdz/image
Requirements
- PHP >= 8.2
- Symfony Filesystem ^7.4
- Symfony Finder ^7.4
- Imagine ^1.3
ext-gd(thumbnails, and Imagine's GD driver for watermarks)
Usage
Loading and Displaying Images
use JDZ\Image\Image; $image = new Image('/path/to/files', 'https://mywebsite.com/'); $image->load('media/photo.jpg', 'media/default.jpg'); $pic = $image->getPic('Photo description'); echo (string)$pic; // <img src="https://mywebsite.com/media/photo.jpg" alt="Photo description" data-orientation="landscape" />
Lazy Loading with Thumbnails
use JDZ\Image\Image; $image = new Image('/path/to/files', 'https://mywebsite.com/', 'thumbs'); $image->lazy = true; $image->targetWidth = 800; $image->cacheLife = 3600; $image->load('media/photo.jpg'); $pic = $image->getPic('Photo'); echo (string)$pic; // src points to thumbnail, data-src points to original
Creating Thumbnails
use JDZ\Image\Thumb; $thumb = new Thumb('/path/to/files', 800, 'thumbs', 3600); $created = $thumb->thumbImage('media/photo.jpg'); echo $thumb->thumbFile; // 'thumbs/media_photo-800.jpg'
Watermark Protection
use JDZ\Image\Copyright; $copyright = new Copyright('/path/to/files', 'protect', 'watermark.png', 'repeat'); // Apply watermark (original backed up to protect/ folder) $copyright->protectImage('media/photo.jpg'); // Restore original $copyright->unprotectImage('media/photo.jpg');
Filesystem Setup
use JDZ\Image\Fs; $fs = new Fs('/path/to/files', 'media', 'thumbs', 'protect'); $fs->check(); // Creates media/, thumbs/, protect/ folders if missing
Image Info
use JDZ\Image\Img; $img = new Img('/path/to/files', 'media/photo.jpg'); if ($img->valid) { echo $img->width; // 1600 echo $img->height; // 1200 echo $img->orientation; // 'landscape' echo $img->ext; // 'jpg' }
Testing
composer test # or vendor/bin/phpunit
Changelog
- 1.1.0 -
Picattribute values are HTML-escaped (a quote was backslashed); a thumb fits insidetargetWidthxtargetWidth, never upscaled (a portrait jumped from 800x1600 to 400x800 around the target width);Copyrighthas asinglemode pasting the watermark once, bottom-right (any type butrepeatpasted nothing), and refuses an unknown type; thumb names hash the folder part (<md5(folder)[0:8]>_<name>-<width>.<ext>, a root file is<name>-<width>.<ext>;a/b_c.jpganda_b/c.jpgcollided) — existing thumb caches are regenerated; the lazyImage::load()honourscacheLife; a missing thumbs folder is created. - 1.0.4 -
getPic()in lazy mode no longer crashes on a picture too small for a thumb; removing the thumbs ofphoto.jpgno longer removes those ofphoto-2.jpg; a BMP / WebP source is a clear "Unsupported image type" error;Copyrightaccepts an upper-case extension. - 1.0.3 - PNG thumbnails keep their transparency (the image type was compared as a string, so the alpha channel was never saved);
ext-gddeclared. - 1.0.2 - PHP >= 8.2, Symfony ^7.4; unit test suite. No code change.
- 1.0.1 - Symfony components ^7.2; the
Buildclass is removed. - 1.0.0 - Initial release.
License
This project is licensed under the MIT License - see the LICENSE file for details.