PHP code example of co-infra / image

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

    

co-infra / image example snippets


use CoInfra\Image\Image;

$did = 'did:plc:bcgltzqazw5tb6k2g3ttenbj';
$cid = 'bafkreieaezg7ybnl2ax54owmaqi357gvwdo3rn3ui7b3wtu6i4yp6t3lbe';

Image::url($did, $cid, ['width' => 800, 'quality' => 80]);
// https://img.infra.coop/blob/did:plc:.../bafkrei.../w=800,q=80

Image::srcset($did, $cid, [400, 800, 1200]);
// .../w=400 400w, .../w=800 800w, .../w=1200 1200w

Image::placeholder($did, $cid);
// .../w=20,q=30,f=webp,blur=10

use CoInfra\Image\{Fit, Format, Operations};

Image::url($did, $cid, new Operations(
    width: 1200,
    height: 630,
    fit: Fit::Cover,
    format: Format::Auto,
));

Image::url($did, $cid, ['preset' => Preset::Avatar, 'quality' => 60]);
// .../p=avatar,q=60

use CoInfra\Image\UrlBuilder;

$images = new UrlBuilder('https://img.example.com');

$images->url($did, $cid, ['width' => 800]);