October: Image cropping when uploading

Created on 14 Aug 2019  路  7Comments  路  Source: octobercms/october

I would like to crop all the images when loading in all form widgets and further store only the cropped version. How can this be done without rewriting all forms of widgets, including the richeditor.
? Thx.

Question

Most helpful comment

@pavelmgn use events. If you're uploading to the medialibrary there's https://octobercms.com/docs/api/media/file/upload and if you're dealing with File model uploads there's

System\Models\File::extend(function ($model) {
    $model->bindEvent('model.afterCreate', function () use ($model) {
        // do stuff here
    });
});

All 7 comments

@pavelmgn use events. If you're uploading to the medialibrary there's https://octobercms.com/docs/api/media/file/upload and if you're dealing with File model uploads there's

System\Models\File::extend(function ($model) {
    $model->bindEvent('model.afterCreate', function () use ($model) {
        // do stuff here
    });
});

@pavelmgn If I'm not mistaken there is a thumbs option field where you can specify the file type widgets to crop on upload so it does it automatically and stores the cropped version internally. Check the documentation!

@SaifurRahmanMohsin he was looking for a more global setting, also I don't think the richeditor supports a thumbs option for the files that are uploaded through it.

@LikeTowers thank you.
if i use the cloud by s3 api as storage no problems should happen?

@pavelmgn it's web development, I'm not going to guarantee you that no problems will happen, but yes, S3 storage is a supported storage driver so you shouldn't have any issues that are October's fault.

@pavelmgn I am using S3 with OCMS and without issues.

@Samuell1 i also use s3 with OCMS, without issues.
@LukeTowers thank you and great respect. I will try this.

Was this page helpful?
0 / 5 - 0 ratings