titi23/image-optimizer-and-resizer

Optimize And Resize Images in server

dev-master 2019-06-21 10:36 UTC

This package is auto-updated.

Last update: 2025-05-22 00:24:53 UTC


README

This package can compress .png, .jpeg and .gif files. Here's how you can use it:

Compress Image, you can optimize the uploaded image or you can save both of them

use titi23\ImageOptimizer\ImageOptimize;

$optimizedImage = new ImageOptimize();

$optimizedImage->ImageOptimized($pathToImage, $saveOriginal);

Resize Image without losing the AspectRatio of the original Image

use titi23\ImageOptimizer\ImageOptimize;

$optimizedImage = new ImageOptimize();

$optimizedImage->ResizeAspectRatio($pathToImage, $percent, $saveOriginal);

Resize Image with new width but not losing AspectRatio of the original image (without stretching the new image)

use titi23\ImageOptimizer\ImageOptimize;

$optimizedImage = new ImageOptimize();

$optimizedImage->ResizeWidth($pathToImage, $newWidth, $saveOriginal);

Installation

You can install the package via composer:

composer require titi23/image-optimizer-and-resizer

Copy and Paste the Service Provider in config/app.php

'providers' => [
 ...
 ...
 titi23\ImageOptimizer\ImageOptimizerServiceProvider::class
 ...
]

After that, publish the package by running this in your terminal

 php artisan vendor:publish --tag=image-optimizer --force

Configuration

In the config directory of your project it must be generated a file called image-optimizer.php

Description for each attribute:

  • upload_dir write the name of the directory where you will upload your images e.g. 'uploads/' -ps: the folder must be inside public.
  • supportedFormat array of the types of images that are allowed.
  • compressRate amount of the compression that image passes through, value between 1 and 100, 1: low quality, 100: high quality
  • resize_percent percent of the resize of the image, value between 1 and 100, e.g. 50, half of the original version

Credits

License

The MIT License (MIT)