PHP code example of goldfinch / image-editor

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

    

goldfinch / image-editor example snippets


use SilverStripe\Assets\Image;
use Goldfinch\ImageEditor\Forms\EditableUploadField;

private static $has_one = [
    'Image' => Image::class,
];

private static $owns = [
    'Image',
];

public function getCMSFields()
{
    $fields = parent::getCMSFields();

    $fields->addFieldsToTab(
        'Root.Main',
        [
            // [
            //     TextField::create('Title')
            //     Other fields ...
            // ],
            ...EditableUploadField::create('Image', 'Image', $fields, $this)->getFields(),
            // [
            //     Other fields ...
            // ],
        ]
    );
    
    return $fields;
}

use SilverStripe\Assets\Image;
use Goldfinch\ImageEditor\Forms\EditableSortableUploadField;

private static $many_many = [
    'Images' => Image::class,
];

private static $many_many_extraFields = [
    'Images' => [
        'SortExtra' => 'Int',
    ]
];

private static $owns = [
    'Images',
];

public function getCMSFields()
{
    $fields = parent::getCMSFields();

    $fields->addFieldsToTab(
        'Root.Main',
        [
            // [
            //     TextField::create('Title')
            //     Other fields ...
            // ],
            ...EditableSortableUploadField::create('Images', 'Images', $fields, $this)->getFields(),
            // [
            //     Other fields ...
            // ],
        ]
    );
    
    return $fields;
}

use SilverStripe\Assets\Image;
use SilverStripe\Forms\GridField\GridField;
use Goldfinch\ImageEditor\Forms\GridField\GridFieldManyManyFocusConfig;

private static $many_many = [
    'Images' => Image::class,
];

private static $many_many_extraFields = [
    'Images' => [
        'SortOrder' => 'Int',
    ]
];

private static $owns = [
    'Images',
];

public function getCMSFields()
{
    $fields = parent::getCMSFields();

    $fields->addFieldsToTab(
        'Root.Main',
        [
            GridField::create('ImageAttributes', 'Images', $this->Images(), GridFieldManyManyFocusConfig::create()),
        ]
    );

    return $fields;
}

use SilverStripe\Assets\Image;
use Goldfinch\ImageEditor\Forms\ImageCoordsField;

private static $has_one = [
    'Image' => Image::class,
];

private static $owns = [
    'Image',
];

public function getCMSFields()
{
    $fields = parent::getCMSFields();

    $fields->addFieldsToTab(
        'Root.Main',
        [
            ImageCoordsField::create($this, 'Image'),
        ]
    );

    return $fields;
}