PHP code example of kaliel / image

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

    

kaliel / image example snippets


public function bootstrap(): void
{
    parent::bootstrap();

    $this->addPlugin('Image');
}

public function initialize(array $config)
{
    $this->addBehavior('Image.Image', [
        'path' => WWW_ROOT . 'assets',
        'fields' => [
            'images' => 'many',
            'main' => 'one'
        ],
    ]);
}

$this->addBehavior('Image.Image', [
	'path' => WWW_ROOT . 'assets',
	'presets' => [
		'overview' => [
			'resize' => [ 200, 200 ], // $image->resize(200, 200);
			'crop' => [ 150, 150] // $image->crop(150,150);
			'canvas' => function($image) {
			 	// you can use callback functions for more advanced stuff
				// do some fancy stuff here

				return $image;
			},
		]
	],
	'fields' => [
		'image' => 'one'
	],
]);

$this->Image->render($entity->field); // Original image
$this->Image->render($entity->field, [ 'preset' => 'presetName' ]); // Preset
$this->Image->render($entity->field, [ 'preset' => 'presetName', 'alt' => 'Cool image' ]); // Preset + image attributes
$this->Image->url($entity->field, 'presetName'); // Returns the image path with an optional preset argument

php composer.phar