fpdev / compress_and_convert
Library to compress and convert images
Installs: 177
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/fpdev/compress_and_convert
Requires
- php: >=8.1
- ext-zip: *
- intervention/image: *
This package is auto-updated.
Last update: 2025-12-17 23:34:40 UTC
README
Hello there! This is my compress and convert library. It is based on the intervention/image package, and its goal is to help users manage images by converting and compressing them.
If you encounter any issues or have questions, feel free to reach out! And don't forget to check out my website at: Francesco Pieraccini Website
Installation
composer require fpdev/compress_and_convert
Usage
-
Create a
CompressAndConvertobject using the constructor, which requires two mandatory parameters:string $extension- extension to convertint $quality- quality to compress
Here's an example of how to create it:
$obj = new FPDEV\Images\CompressAndConvert(extension: 'webp', quality: 50);
This will create an object of
CompressAndConvertImagesthat can be used to convert images to webp format and compress them to 50% quality. -
compressConvertAndSavefunction:This function requires three mandatory parameters:
array $fileArray- [filename, ext]string $whereToGetFile- path/to/dir with original filesstring $whereToSaveFile- path/to/dir where to put output files
This function utilizes
ImageManagerto convert and compress the file as you set in the constructor. Once completed, the converted and compressed file will be saved in the$whereToSaveFiledirectory and the function returns the compressed file name. -
getFileExtAllowedfunction:This is a getter function that returns the allowed file extensions.
-
getFileArraysFromDirfunction:This function requires one mandatory parameter:
string $dir- path/to/dir to scan
This function scans the
$dirand returns an array with accepted and discarded files in this format:$acceptedFiles = ['ext', 'filename']; $discardedFiles = ['filename'];
-
zipFilesfunction:This function requires one mandatory parameter:
string $dirWithFiles- path/to/dir with files to zip
This function creates a zip file containing all the images in
$dirWithFiles. The zip file will be saved in the same directory. -
removeFilesFromDirfunction:This function requires one mandatory parameter:
string $dir- path/to/dir
This function deletes all the files in
$direxcept zip files and .gitkeep file. Call this function if you want to clean the output from all compressed images but maintain the zip file. -
filenameToFileArrayfunction:This function requires one mandatory parameter:
string $filename- a filename
This function returns a fileArray that can be used in the
compressConvertAndSavefunction, derived from the given filename. The fileArray has the format:[filename, ext]
License
This library is licensed under the MIT License - see the LICENSE file for details