masum-nishat/image-resize-php

Resize image to desire file size by only one compression

v1.1.0 2019-11-17 19:42 UTC

This package is auto-updated.

Last update: 2024-09-18 06:45:23 UTC


README

PHP library to resize image to desire file size by only one compression.

Warning

This is a development package. I encourage not to use in production environment.

Please inform if any bug or security issue or any other problem found.

Any suggestion will be taken seriously.

Setup

This package is available through Packagist with the vendor and package identifier the same as this repo.

If using Composer, run following command:

composer require "masum-nishat/image-resize-php":"^1.1.0"

Note: This library uses GD class which do not support resizing animated gif files

Resize

Only supported resizing param is according to file size. Image dimension will be changed and final image will be under 250KB (Default).

imageResize::convert('image.jpg', 'image-converted.jpg');
//or
imageResize::convert('image.png', 'image-converted.png');

Let the extension detect automatically from mime type:

imageResize::convert('image.jpg', 'image-converted');
//or
imageResize::convert('image.png', 'image-converted');

Declare required maximum size:

imageResize::$targetSize = 300000; //maximum 300KB

imageResize::convert('image.jpg', 'image-converted');
//or
imageResize::convert('image.png', 'image-converted');

This class creat unique temp directory and delete it after using. To use custom temp directory and not delete temp components (useful for debugging):

imageResize::$tempDir = 'path/to/temp/folder';

imageResize::convert('image.jpg', 'image-converted');
//or
imageResize::convert('image.png', 'image-converted');

Supported Image Types

  • IMAGETYPE_JPEG
  • IMAGETYPE_PNG
  • IMAGETYPE_GIF

Quality

Maximum quality is selected by default.

Quality change param is not implemented yet;

Exceptions

Exception handling not implemented yet.