PHP code example of josbeir / image
1. Go to this page and download the library: Download josbeir/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/ */
josbeir / image example snippets
Plugin::load('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