1. Go to this page and download the library: Download fynduck/files-upload library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
fynduck / files-upload example snippets
use Fynduck\FilesUpload\UploadFile;
UploadFile::file($request->file('file')) //or $request->get('base64'), //optional, default use file name or random in case base64
->setOverwrite('old_name.jpg') //optional, remove file with old name
->setSizes(['xs' => ['width' => 100, 'height' => 100]]) //(optional) if need other sizes
->setBackground('#000000') //optional
->setBlur(0) //optional, use values between 0 and 100
->setBrightness(0) //optional, use values between -100 and +100. brightness 0 for no change
->setGreyscale(true) //optional true or false default is false
->setOptimize(true) //optional
->setEncodeFormat() //optional, ['jpeg', 'jpg', 'png', 'gif', 'webp', 'avif']
->setEncodeQuality() //optional, use values between 0 and 100
->queue() //optional, generate sizes in the background (see below)
->save('resize'); //save option resize, crop default is resize
UploadFile::file($request->file('file'))
->setFolder('Post')
->setName('image_name')
->setSizes(['xs' => ['width' => 100, 'height' => 100], 'md' => ['width' => 400, 'height' => 400]])
->queue() // or ->queue('redis', 'images') ; ->queue(perSize: false) for one job for all sizes
->save(); // returns the original filename right away
// config/files-upload.php
'queue' => [
'enabled' => false, // set true to always resize in the background
'connection' => null,
'queue' => null,
'per_size' => true, // one job per size (parallel) vs a single job for all sizes
],
use Fynduck\FilesUpload\ManipulationImage;
ManipulationImage::load($pathImage)
->setDisk('storage') //default is public
->setFolder('Post')
->setSizes(['xs' => ['width' => 100, 'height' => 100]])
->setName('image_name.jpg') //name with extension
->setOverwrite('old_name.jpg') //optional, remove file with old name
->setBackground('#000000') //optional
->setBlur(0) //optional, use values between 0 and 100
->setBrightness(0) //optional, use values between -100 and +100. brightness 0 for no change
->setGreyscale(true) //optional true or false default is true
->setOptimize(true) //optional
->setEncodeFormat() //optional, ['jpeg', 'jpg', 'png', 'gif', 'webp', 'avif']
->setEncodeQuality() //optional, use values between 0 and 100
->save('resize'); //save option resize, resize-crop, crop default is resize
use Fynduck\FilesUpload\ManipulationImage;
ManipulationImage::load('image_name.jpg')
->setOptimize(true)
->optimize('path_to_image');