kennynguyeenx / image-service
Provide some functions to convert images.
Requires
- php: >=7.0
- ext-imagick: *
- ext-mbstring: *
- intervention/image: ^2.4
Requires (Dev)
- phpunit/phpunit: ~4.8|~5.2
This package is not auto-updated.
Last update: 2025-03-30 08:02:02 UTC
README
Provide some functions to manipulate images
Features
- Resize image
- Set background color for image
- Create bigger image with old image in the center
- Convert image to the other type
- Dependencies: imagemagick, webp
- PSR-4 compatible.
- Compatible with PHP >= PHP 7.
Installation
-
You can download image-service through https://github.com/kennynguyeenx/image-service.
-
image-service requires the Multibyte String extension and the Imagick extension from PHP.
-
Typically you can use the configure option
--enable-mbstring
while compiling PHP to have the Multibyte String extension. More information can be found in the PHP documentation. -
Imagick is a native php extension to create and modify images using the ImageMagick API. More information can be found in the PHP documentation.
Usage
- Resize image:
use Kennynguyeenx\ImageService\ImageService; try { $imageService = new ImageService(); $imageService->manipulateImage($imageUrl, $options, $outputImagePath, $outputFormat); } catch (Exception $exception) { exit($exception->getMessage()); }
-
$options should consist these keys: width (width of new image), height (height of new image), background (background color of new image if using canvas)
-
I created a file to run in console to manipulate images as an example of using this class
-
It's located at bin directory with name manipulate_image.php
-
You can follow these steps to resize and convert image to the other type:
- Save a image under the folder that you want. For me, i save it under images/source folder as example_image.png
- This image have size is 300x300. We will try to resize it to 200x200 and convert it from png to gif. We can run this command:
$ php ./bin/manipulate_image.php ./images/source/example_image.png 200x200_ ./images/destination/updated_image.png gif
- This is the result: