PHP code example of sirv / sirv-image

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

    

sirv / sirv-image example snippets


use Sirv\SirvImage;

$url = (new SirvImage('https://demo.sirv.com/image.jpg'))
    ->resize(300, 200)
    ->format('webp')
    ->quality(80)
    ->toUrl();

// https://demo.sirv.com/image.jpg?w=300&h=200&format=webp&q=80

// Full image URL
new SirvImage('https://demo.sirv.com/image.jpg');

// Base URL + path
new SirvImage('https://demo.sirv.com', '/image.jpg');

->text('Hello', [
    'fontSize' => 32,
    'fontFamily' => 'Arial',
    'fontStyle' => 'italic',
    'fontWeight' => 700,
    'color' => 'white',
    'opacity' => 80,
    'outlineWidth' => 2,
    'outlineColor' => 'black',
    'backgroundColor' => 'red',
    'backgroundOpacity' => 50,
    'align' => 'center',
    'position' => 'center',
    'positionX' => 10,
    'positionY' => 20,
    'positionGravity' => 'northwest',
])

->watermark('/logo.png', [
    'position' => 'southeast',
    'opacity' => 50,
    'scaleWidth' => '20%',
    'scaleOption' => 'fit',
    'rotate' => 45,
    'layer' => 'front',
])

->canvas(['width' => 800, 'height' => 600, 'color' => 'ffffff',
          'aspectRatio' => '16:9', 'borderWidth' => 10])
->frame(['style' => 'solid', 'color' => '333', 'width' => 5,
         'rimColor' => 'gold', 'rimWidth' => 2])

$url = (new SirvImage('https://demo.sirv.com/products/shoe.jpg'))
    ->resize(800, 600, 'fill')
    ->format('webp')
    ->quality(85)
    ->watermark('/brand-logo.png', ['position' => 'southeast', 'opacity' => 30])
    ->toUrl();

$url = (new SirvImage('https://demo.sirv.com/photo.jpg'))
    ->colortone('sepia')
    ->vignette(40)
    ->frame(['style' => 'solid', 'color' => 'f5e6d3', 'width' => 20])
    ->toUrl();