PHP code example of lamka02sk / picturium

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

    

lamka02sk / picturium example snippets


use Picturium\Enum\Format;
use Picturium\Picturium;

use function Picturium\img;

Picturium::configure(
    url: 'https://img.example.com',
    secret: $_ENV['PICTURIUM_SECRET'],
    defaults: img()->dpr([1, 2, 3])->quality(80)->format(Format::Auto),
);

<?= img($product->photo)
    ->width(640)
    ->aspectRatio('4/3')
    ->alt($product->name)
    ->lazy() 

$image = img('photos/cat.jpg')->width(400)->dpr([1, 2]);

$image->src();        // One signed URL
$image->srcset();     // "... 1x, ... 2x"
$image->urls();       // ['1x' => '...', '2x' => '...']
$image->attributes(); // Raw attribute array for framework adapters
$image->attrs();      // Escaped attributes for an existing <img>
$image->toHtml();     // A complete <img> element

<img <?= img($product->photo)->width(400)->attrs() 

use Picturium\Enum\Format;

use function Picturium\picture;

<?= picture('hero.jpg')
    ->quality(80)
    ->dpr([1, 2])
    ->images(fn ($image) => [
        $image->maxWidth(640)->portrait()->width(640)->aspectRatio('1/1'),
        $image->minWidth(641)->format(Format::Avif)->width(1920)->height(1080),
    ])
    ->alt('A mountain at sunrise') 

use Picturium\Enum\{Anchor, Extend, Fit, Format, Gravity, Metadata, Resample, Rotate};

img('catalogue/shoes.jpg')
    ->width(800)->height(600)->aspectRatio('4/3')
    ->fit(Fit::Contain)->gravity(Gravity::Attention)->extend(Extend::Mirror)
    ->resample(Resample::Lanczos3)->upsize()->padding(10, 20)
    ->rotate(Rotate::Left)->background('111827')
    ->quality(82)->format(Format::Webp)->metadata(Metadata::Icc)
    ->crop(width: 800, height: 600, gravity: Gravity::Attention)
    ->watermark(text: 'ACME', anchor: Anchor::BottomRight, opacity: 40)
    ->download('shoes.webp');

'defaults' => ['quality' => 80, 'format' => Picturium\Enum\Format::Auto],

'presets' => [
    'hero' => ['width' => 1600, 'dpr' => [1, 2]],
    'thumb' => ['width' => 200, 'aspect-ratio' => '1/1', 'fit' => Picturium\Enum\Fit::Cover],
    'banner' => ['quality' => 80, 'sources' => [
        ['min-width' => 1024, 'width' => 1920],
        ['max-width' => 640, 'portrait' => true, 'width' => 640, 'aspect-ratio' => '1/1'],
    ]],
],

use Picturium\Laravel\Casts\AsPicturiumImage;

protected function casts(): array
{
    return [
        'hero' => AsPicturiumImage::class . ':hero',
        'avatar' => AsPicturiumImage::class . ':thumb,cdn',
    ];
}

return Inertia::render('Products/Show', ['product' => $product]);

// config/bundles.php
return [
    // ...
    Picturium\Symfony\PicturiumBundle::class => ['all' => true],
];

use Picturium\Image;

#[ORM\Column(type: 'picturium_image.hero', nullable: true)]
public ?Image $hero = null;


bash
php artisan vendor:publish --tag=picturium-config