Skip to content

SimpleImageCompressor is a tiny simple PHP image resizer/compressor lib which allows you to resize and compress any image easily on the fly.

License

Notifications You must be signed in to change notification settings

Geckon01/simple-image-compressor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SimpleImageCompressor

Version Lecense Downloads Codacy Badge

SimpleImageCompressor - is a tiny simple PHP image resizer lib which allows you to resize and compress any image easily on the fly.

Installation

With composer

composer require "geckon01/simple-image-compressor"

Without composer

  1. Download latest release here.
  2. Unpack archive to any folder of your project you wish.
  3. Load main lib files:
require "src/SimpleImageCompressor.php";  
require "src/CompressedImage.php";
use geckon01\SimpleImageCompressor\SimpleImageCompressor;

Usage

To resize and compress your image you can use next code:

$resolutionTargetPercent = 50;
$targetQuality = 50;
$compressor = SimpleImageCompressor::load("image.png");
$compressedImage = $compressor->resizeAndCompress($resolutionTargetPercent, $targetQuality);
$compressedImage->toFile("image");

load method supports loading from local file, or you can specify any valid URL image link like this:

$compressor = SimpleImageCompressor::load("https://example.com/image.jpg");

This lib support chaining, so you can do something like this:

SimpleImageCompressor::load("image.png")
	->resizeAndCompress(50, 50)
	->toFile("image");

Note that you don't need to specify file extension. The lib will save file with proper one automatically.

Output format

You can specify output format. Supported output fomats are:

$compressedImage->toFile("image");
$compressedImage->toBase64();
$compressedImage->toGdImage();

Max/min height/width

Also you can set approximate minumum and maximum image size.

$compressor->setApproxMinimumHeight(500);  
$compressor->setApproxMinimumWidth(500);

Note that Due to saving proportion lib can't guarantee that width and height be equals max and min . As example, if we have original image 1920x1080 which we want to get 50% of original resolution and save original 16x9 aspect ration the reduced image must be 960x540.

License

This software is licensed under the MIT License. View the license.

About

SimpleImageCompressor is a tiny simple PHP image resizer/compressor lib which allows you to resize and compress any image easily on the fly.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages