Download the PHP package jackal/image-merge without Composer
On this page you can find all versions of the php package jackal/image-merge. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package image-merge
Image Merge
A simple PHP library to manipulate images. It supports JPEG, PNG, GIF and WebP.
Upgrading from 0.4.x? Version 1.0 has a new, safer API. See UPGRADE-1.0.md.
Requirements
- PHP >= 8.2 with the
gd(JPEG/PNG/WebP/FreeType support) andexifextensions - ImageMagick (
magickorconvert) only for theDistortioneffect
Getting Started
Install the library with composer
Usage
Loading an image
Pick the factory that matches your source:
Minimal example
Get the image content
Save the image to a path
Get a Response object (compatible with Symfony projects)
toJPG(), toGIF() and toWebP() work the same way.
Operations
resize
At least one parameter is required. If only one is passed, the aspect ratio of the image is kept
If both are passed, the image may be stretched
thumbnail
Like resize, but if the aspect ratio doesn't match it crops the image (using cropCenter)
rotate
Rotate the image (counterclockwise)
*For angles that aren't multiples of 90, the empty areas are filled with transparent pixels.
flipHorizontal and flipVertical
grayScale
Add a grayscale filter to the image
brightness and contrast
blur
Add a blur effect to the image
pixelate
Add a "pixel" effect to the image
crop and cropCenter
Crop the image starting from the x and y coords, with the given output size.
The area must be inside the image, otherwise an InvalidArgumentException is thrown
Crop at the center of the image, with the given output size
cropPolygon
Keep only the area inside the polygon (at least three x,y points), making the rest transparent
border
Add a border to the image (drawn inside the image)
merge
Draw another image on top, at the given position
Experimental features that will likely change in the future
addText
Add text to the image
addSquare
Add a color-filled square to the image
Security
The library is designed to be safe with untrusted input, within these limits:
- Remote files:
fromUrl()accepts onlyhttpandhttps, refuses private, loopback, link-local and reserved addresses, doesn't follow redirects, and enforces a timeout and a maximum size. Pass a configuredJackal\ImageMerge\Loader\UrlLoaderto change these settings, e.g.new UrlLoader(timeout: 5, maxBytes: 5_000_000). The host is checked before the request is made, so DNS rebinding is not prevented. If you load URLs supplied by users, also restrict outbound traffic at the network level. - Local files:
fromPath()refuses stream wrappers such asphar://orphp://. Never pass a path built from user input without validating it. -
Resource limits: image dimensions and file size are checked from the header before decoding, to stop "decompression bombs". Defaults are 50 megapixels, 50 MB and a blur level of 100. You can change them globally:
- Metadata: EXIF, IPTC and XMP values come from the file itself and are attacker-controlled. Escape them before displaying them, for example in HTML.
Development
Or one tool at a time:
| Command | What it does |
|---|---|
composer test |
Run the PHPUnit suite |
composer cs / composer cs-fix |
Check / fix code style (php-cs-fixer, config in .php-cs-fixer.dist.php) |
composer rector / composer rector-fix |
Check / apply automated refactorings (Rector, config in rector.php) |
When you run the fixers, run Rector first and php-cs-fixer second, because Rector's output is then reformatted.
Tests that download a real image are in the network group. Skip them offline with vendor/bin/phpunit --exclude-group network.
The suite needs GD, EXIF and ImageMagick. If you don't have them locally, use the bundled Docker image (the PHP_VERSION build argument chooses the PHP version):
CI (GitHub Actions) runs the tests on PHP 8.2, 8.3, 8.4 and 8.5, plus PHP 8.2 with the lowest allowed dependencies. It also runs composer validate --strict, composer audit, and the Rector and php-cs-fixer checks.
Author
- Luca Giacalone (AKA JackalOne)
License
This project is licensed under the MIT License, see LICENSE.
The bundled font Liberation Sans (src/Resources/Fonts/LiberationSans-Regular.ttf)
is licensed under the SIL Open Font License 1.1, see src/Resources/Fonts/LICENSE-LiberationSans.txt.
All versions of image-merge with dependencies
ext-gd Version *
ext-exif Version *
symfony/http-foundation Version ^6.4 || ^7.0
symfony/process Version ^6.4 || ^7.0