PHP code example of mehr-it / levi-assets

1. Go to this page and download the library: Download mehr-it/levi-assets 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/ */

    

mehr-it / levi-assets example snippets


// config/leviAssets.php

return [
    'collections' => [
        'productImages' => [
            'storage'        => 'local',
            'storage_path'   => 'products/images',
            'public_storage' => 's3',
            'public_path'    => 'static/pi',
            'virus_scan'     => true,
            'build' => [
                'small_jpg' => [
                    'imgMaxSize:100,75',
                    'imgFormat:jpg',
                    'imgOptimize',
                ],
                'small_webp' => [
                    'imgMaxSize:100,75',
                    'imgFormat:webp',
                ],
                'large_jpg' => [
                    'imgMaxSize:800,600',
                    'imgFormat:jpg',
                    'imgOptimize',
                ],
                'large_webp' => [
                    'imgMaxSize:800,600',
                    'imgFormat:webp',
                ],
            ],
            'link_filters' => [
                'webp:small_webp,large_webp'
            ]
        ],
    ],
    'builders' => [
        'imgMaxSize'  => ImageMaxSizeBuilder::class,
        'imgFormat'   => ImageFormatBuilder::class,
        'imgOptimize' => OptimizeImageBuilder::class,
    ]
]

// config/leviAssets.php

return [
    'collections' => [
        'productImages' => [
            /*
             * ...
             */
            'build' => [
                ':small' => [
                     'imgMaxSize:100,75',
                ],
                'small_jpg:small' => [
                    'imgFormat:jpg',
                ],
                'small_webp:small' => [
                    'imgFormat:webp',
                ],
            ],
        ],
    ],
]