PHP code example of tobse / cakephp-image-cropper

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

    

tobse / cakephp-image-cropper example snippets


public function bootstrap(): void
{
    parent::bootstrap();
    $this->addPlugin('ImageCropper');
}

public function initialize(): void
{
    parent::initialize();
    $this->loadHelper('Form', ['className' => 'ImageCropper.Cropper']);
    $this->loadHelper('Html'); // 

<?= $this->fetch('css') 

echo $this->Form->create($entity, ['type' => 'file']);
echo $this->Form->control('image', [
    'type' => 'cropper',
    'options' => [
        'aspectRatio' => '16/9',
        'modalTitle' => 'Crop the header image',
    ],
]);
echo $this->Form->button('Save');
echo $this->Form->end();

public function initialize(): void
{
    parent::initialize();
    $this->loadComponent('ImageCropper.SaveImage');
}

public function add()
{
    $entity = $this->Articles->newEmptyEntity();
    if ($this->request->is('post')) {
        $this->SaveImage->process('image');
        $entity = $this->Articles->patchEntity($entity, $this->request->getData());
        if ($this->Articles->save($entity)) {
            // handle the (now cropped) uploaded file as usual
        }
    }
    $this->set(compact('entity'));
}

// src/View/AppView.php
$this->loadHelper('Form', [
    'className' => 'ImageCropper.Cropper',
    'autoInclude' => false,
]);

// your layout or template
$this->Html->script('ImageCropper.image-cropper', ['block' => true, 'defer' => true]);
$this->Html->css('my-cropper-theme', ['block' => true]); // must