PHP code example of jukuan / img-to-web

1. Go to this page and download the library: Download jukuan/img-to-web 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/ */

    

jukuan / img-to-web example snippets


try {
    $imagePath = (new ImgConvertorService())
        ->setDirs($resizedImgDir, __DIR__)
        ->prepareImagePath();
    (new Response())->doImageOutput($imagePath);
} catch (\Exception $e) {
    // handle an error
}
 web.php

use Jukuan\ImgToWeb\Service\ImgConvertorService;
use Jukuan\ImgToWeb\Http\Response as ImgToWebResponse;

Route::get('img', function ()
{
    $sourceImgDir = public_path('');
    $resizedImgDir = public_path('resized');

    try {
        $imagePath = (new ImgConvertorService())
            ->setDirs($resizedImgDir, $sourceImgDir)
            ->prepareImagePath();
        (new ImgToWebResponse())->doImageOutput($imagePath);
    } catch (\Exception $e) {
        abort(404);
    }
});