PHP code example of approached / laravel-image-optimizer

1. Go to this page and download the library: Download approached/laravel-image-optimizer 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/ */

    

approached / laravel-image-optimizer example snippets


Approached\LaravelImageOptimizer\ServiceProvider::class,

Route::post('admin/image/upload', function () {
    $picture = $request->file('picture');

   ...
})->middleware('AutoImageOptimizer');

public function store(Request $request, ImageOptimizer $imageOptimizer)
    {
        $picture = $request->file('picture');

        // optimize
        $imageOptimizer->optimizeUploadedImageFile($picture);

        // save
        Storage::put('/my/cool/path/test.jpg', File::get($picture));

        ...
    }

php artisan vendor:publish --tag=imageoptimizer