PHP code example of sujan97825 / laravel-webp-converter

1. Go to this page and download the library: Download sujan97825/laravel-webp-converter 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/ */

    

sujan97825 / laravel-webp-converter example snippets


'providers' => [
    // ...
    Sujan\\LaravelWebpConverter\\WebpConverterServiceProvider::class,
    // ...
],

'aliases' => Facade::defaultAliases()->merge([
    // ...
    'WebpConverter' => Sujan\LaravelWebpConverter\Facades\WebpConverter::class,
    // ...
])->toArray(),

use Sujan\LaravelWebpConverter\Facades\WebpConverter;

WebpConverter::webpImage($file, $filename, $location, $width = null, $height = null, $quality = null);


/**
 * Convert image to webp.
 *
 * @param file $file
 * @param string $filename
 * @param string $location
 * @param integer $width
 * @param integer $height
 * @param integer $quality
 *
 * @return string
 * @throws \Exception
 */
public function webpImage(
    $file,
    $filename,
    $location,
    $width = null
    $height = null
    $quality = null
)



  $file = $request->file("image"); //Request File
  $filename="abc"; //Image Name
  $location="assets/images/"; //Image Upload Location
  $width=500; // Image Width,If You Want To Resize.Default Null.
  $height=250; // Image Height,If You Want To Resize.Default Null.
  $quality=100 //Image Quality Can Be Used [ 1-100 ],Default 100.
  

return [
    /*
    |--------------------------------------------------------------------------
    | Default Image  Quality
    |--------------------------------------------------------------------------
    |
    | Default 100, image quality can be used [1-100]
    |
    */
    'quality' => 100,
];



sh
php artisan vendor:publish --provider="Sujan\LaravelWebpConverter\WebpConverterServiceProvider"