mirror of
https://github.com/Geckon01/simple-image-compressor.git
synced 2026-06-17 08:47:51 +00:00
Update README.md
This commit is contained in:
@@ -19,9 +19,9 @@ composer require "geckon01/simple-image-compressor"
|
|||||||
|
|
||||||
### Without composer
|
### Without composer
|
||||||
|
|
||||||
1. Download latest release [here](https://github.com/Geckon01/simple-image-compressor/releases).
|
1. Download latest release [here](https://github.com/Geckon01/simple-image-compressor/releases).
|
||||||
2. Unpack archive to any folder of your project you wish.
|
2. Unpack the archive to your project directory.
|
||||||
3. Load main lib files:
|
3. Include the library files:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
require "src/SimpleImageCompressor.php";
|
require "src/SimpleImageCompressor.php";
|
||||||
@@ -31,7 +31,7 @@ use geckon01\SimpleImageCompressor\SimpleImageCompressor;
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
To resize and compress your image you can use next code:
|
Resize and compress an image:
|
||||||
```php
|
```php
|
||||||
$resolutionTargetPercent = 50;
|
$resolutionTargetPercent = 50;
|
||||||
$targetQuality = 50;
|
$targetQuality = 50;
|
||||||
@@ -43,14 +43,13 @@ load method supports loading from local file, or you can specify any valid URL i
|
|||||||
```php
|
```php
|
||||||
$compressor = SimpleImageCompressor::load("https://example.com/image.jpg");
|
$compressor = SimpleImageCompressor::load("https://example.com/image.jpg");
|
||||||
```
|
```
|
||||||
This lib support chaining, so you can do something like this:
|
Method chaining is supported:
|
||||||
```php
|
```php
|
||||||
SimpleImageCompressor::load("image.png")
|
SimpleImageCompressor::load("image.png")
|
||||||
->resizeAndCompress(50, 50)
|
->resizeAndCompress(50, 50)
|
||||||
->toFile("image");
|
->toFile("image");
|
||||||
```
|
```
|
||||||
> Note that you don't need to specify file extension. The lib will save
|
> Note: File extensions are automatically added. Use toFile("filename") without extension.
|
||||||
> file with proper one automatically.
|
|
||||||
|
|
||||||
### Output format
|
### Output format
|
||||||
You can specify output format. Supported output fomats are:
|
You can specify output format. Supported output fomats are:
|
||||||
@@ -64,14 +63,14 @@ $compressedImage->toBase64();
|
|||||||
```php
|
```php
|
||||||
$compressedImage->toGdImage();
|
$compressedImage->toGdImage();
|
||||||
```
|
```
|
||||||
### Max/min height/width
|
### Size Constraints
|
||||||
Also you can set approximate minumum and maximum image size.
|
Set approximate minimum dimensions (aspect ratio preserved):
|
||||||
```php
|
```php
|
||||||
$compressor->setApproxMinimumHeight(500);
|
$compressor->setApproxMinimumHeight(500);
|
||||||
$compressor->setApproxMinimumWidth(500);
|
$compressor->setApproxMinimumWidth(500);
|
||||||
```
|
```
|
||||||
> Note that Due to saving proportion lib can't guarantee that width and height be equals max and min .
|
> Note actual dimensions may differ due to aspect ratio preservation.
|
||||||
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.
|
Example: 1920×1080 image reduced to 50% becomes 960×540 (maintaining 16:9).
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user