Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/leongrdic/php-imgman
image processing library that can downscale, compress and convert images using PHP-GD native functions
https://github.com/leongrdic/php-imgman
compress-images image-processing php php-gd php8 thumbnail
Last synced: about 1 month ago
JSON representation
image processing library that can downscale, compress and convert images using PHP-GD native functions
- Host: GitHub
- URL: https://github.com/leongrdic/php-imgman
- Owner: leongrdic
- Created: 2022-01-26T20:44:26.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-04-15T23:23:48.000Z (over 1 year ago)
- Last Synced: 2024-09-30T14:01:21.179Z (about 1 month ago)
- Topics: compress-images, image-processing, php, php-gd, php8, thumbnail
- Language: PHP
- Homepage:
- Size: 8.79 KB
- Stars: 9
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# imgman
This library uses GD and EXIF (optional) PHP extensions so make sure you have them installed.
It also uses the latest PHP 8.1 features and backwards compatibility isn't yet supported.
## Install:
```
composer require leongrdic/imgman
``````php
use \Le\ImgMan\{ImgMan, ImageFormat};
```## Supported formats
### Input
- any image format supported by php-gdInput methods: `fromDataUrl()`, `fromString()`, `fromFile()`
### Output
Call the `output()` method with the wanted output format:
- `ImageFormat::jpeg`
- `ImageFormat::png`
- `ImageFormat::webp` (make sure your php-gd is configured to work with webp)After that use: `toDataUrl()`, `toString()`, `toFile()`
## Example usages
```php
$rawImageBytes = (new ImgMan)
->fromDataUrl($dataUrlFromJS)
->cacheExif()
->downscale(2048)
->rotateFromExif() // rotating after downscaling should use less memory and be a bit faster
->output(ImageFormat::jpeg, quality: 75)
->toString();
``````php
(new ImgMan)
->fromFile('example.png')
->downscale(1920, 1080)
->output(ImageFormat::png)
->toFile(); // use input filename (replace original file)
``````php
$dataUrl = (new ImgMan)
->fromString($rawImageBytes)
->output(ImageFormat::webp, quality: 80)
->toDataUrl();
```# Notice
This library hasn't yet been fully tested and is to be used at your own responsibility.
Any feedback and improvement suggestions are appreciated!