Resize images on boot

How would you resize images when they were uploaded?

There is, for example, a function: $ Image-> resizeByWidth (width)

Where can it be implemented to resize images that are uploaded?

How can I add it to the following boot example:

class GalleryPage extends Page {

    private static $many_many = array(
        'GalleryImages' => 'Image'
    );

    function getCMSFields() {

        $fields = parent::getCMSFields();

        $fields->addFieldToTab(
            'Root.Upload', 
            $uploadField = new UploadField(
                $name = 'GalleryImages',
                $title = 'Upload one or more images (max 10 in total)'
            )  
        );
        $uploadField->setAllowedMaxFileNumber(10);

        return $fields;        
    }   

thanks

+2
source share
3 answers

This is automatically performed by the CMS. When you go to use the image in your template, you specify its size and it will be resized as soon as you save or publish (if it has not already been)

+2
source

CMS, RAW , . 5MB JPG, , .

SilverStripe 2.4+, ResampleUpload. .

SilverStripe 3+, , DataExtension DataObjectDecorator, SS3 , , , , , onAfterUpload onAfterWrite, Image SS 3.

+2

, SS SS . , : https://github.com/heyday/silverstripe-optimisedimage

mod root.

mysite/_config/config.yml, ( ).

Image:
  extensions:
    - ResampleImage

config.yml (x = , y = , ). , ( ), .

ResampleImage:
  max_x: 2000
  max_y: 2000
0

Source: https://habr.com/ru/post/1606447/


All Articles