PHP code example of jorisnoo / statamic-imageboss

1. Go to this page and download the library: Download jorisnoo/statamic-imageboss 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/ */

    

jorisnoo / statamic-imageboss example snippets


'presets' => [
    'thumbnail' => [
        'min' => 200,      // minimum srcset width
        'max' => 700,      // maximum srcset width
        'ratio' => 1,      // aspect ratio (optional)
        'interval' => 250, // width step (optional)
    ],
    'hero' => [
        'min' => 640,
        'max' => 3840,
    ],
],

use Noo\StatamicImageboss\Concerns\HasImagePresetHelpers;
use Noo\StatamicImageboss\Contracts\ImagePreset;

enum Preset: string implements ImagePreset
{
    use HasImagePresetHelpers;

    case Default = 'default';
    case Thumbnail = 'thumbnail';
    case Card = 'card';
    case Hero = 'hero';

    /**
     * @return array{min: int, max: int, ratio?: float, interval?: int}
     */
    public function config(): array
    {
        return match ($this) {
            self::Default => ['min' => 320, 'max' => 2560],
            self::Thumbnail => ['min' => 200, 'max' => 700, 'ratio' => 1, 'interval' => 250],
            self::Card => ['min' => 300, 'max' => 800, 'ratio' => 4 / 5],
            self::Hero => ['min' => 640, 'max' => 3840],
        };
    }
}

Preset::Hero->min();      // 640
Preset::Hero->max();      // 3840
Preset::Card->ratio();    // 0.8
Preset::Thumbnail->interval(); // 250

use Noo\StatamicImageboss\Facades\ImageBoss;

// Single URL
$url = ImageBoss::from($asset)->width(800)->url();
$url = ImageBoss::from($asset)->width(800)->ratio(16/9)->url();

// Responsive srcset with preset
$srcset = ImageBoss::from($asset)->preset('hero')->srcsetString();
// Or
$srcset = ImageBoss::from($asset)->preset(Preset::Hero)->srcsetString();

// Custom configuration
$srcset = ImageBoss::from($asset)
    ->min(300)
    ->max(1200)
    ->interval(200)
    ->ratio(4/5)
    ->srcsetString();

// Width only - no aspect ratio constraint
ImageBoss::from($asset)->rias();
// => https://img.imageboss.me/your-source/width/{width}/format:auto/assets/image.jpg

// With height - maintains aspect ratio via {height} placeholder
ImageBoss::from($asset)->height(630)->rias();
// => https://img.imageboss.me/your-source/cover/{width}x{height}/format:auto/assets/image.jpg

// With ratio - same result, height calculated by lazysizes
ImageBoss::from($asset)->ratio(16/9)->rias();
// => https://img.imageboss.me/your-source/cover/{width}x{height}/format:auto/assets/image.jpg
bash
php artisan vendor:publish --tag="imageboss-config"