PHP code example of sivka / img-5

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

    

sivka / img-5 example snippets


$params = array(
    'width' => 100,
    'height' => 150,
    'crop' => false,
    'watermark' => '',
    'wm_position' => 'center',
    'wm_opacity' => 0.6,
    'quality' => 80,
    'wm_text' => '',
    'wm_text_color' => '#FFFFFF',
    'wm_text_size' => 64,
    'wm_text_font' => 'arial.ttf',
    'default' => ''
);
100, true);
//returns /path/to/thumbs/100x100cp/file.jpg

//with setting cache directory
Img::setCacheDirectory('cache');
$src = Img::get('path/to/file.jpg', 100, 100, true);
//returns /cache/path/to/thumbs/100x100cp/file.jpg

static get($filepath, $params);
static get($filepath, $width, [$height, [$crop]]);
convert image and returns relative path to converted images

static setCacheDirectory($path);
sets path to cache directory

static setDocRoot($docRoot);
set DOCUMENT_ROOT, use this if $_SERVER['DOCUMENT_ROOT'] is not real absolute path to home directory

static setPlaceholder($filepath);
set path to placeholder image. If source image does not exists, path to placeholder will be returned.