wintercms / winter

Free, open-source, self-hosted CMS platform based on the Laravel PHP Framework.
https://wintercms.com
MIT License
1.34k stars 191 forks source link

crop method not called in ImageResizer #1185

Open mjauvin opened 3 weeks ago

mjauvin commented 3 weeks ago

Winter CMS Build

dev-develop

PHP Version

8.1

Database engine

MySQL/MariaDB

Plugins installed

No response

Issue description

When using the ImageResizer with mode:crop, the crop() method never gets called.

Steps to replicate

Twig markup:

<img src="{{ 'image-path' | theme | resize(200, 100, {mode: 'crop'}) }}">

Plugin boot method:

Event::listen('system.resizer.processCrop', function ($resizer, $localTempPath) {
    trace_log("this won't show up");
});

Workaround

No response

bennothommo commented 3 weeks ago

@mjauvin I'm not sure that using mode: crop is synonymous with using the crop command in the ImageResizer class - it appears that crop is just a shortcut method. Further, it appears that the resize filter is passing everything through the resize method anyway, which just filters down to the Winter\Storm\Database\Attach\Resize utility class which does the actual resizing/cropping.

My guess is that the crop method was being set up to be used for a separate crop filter in Twig.

LukeTowers commented 3 weeks ago

@mjauvin could you provide an example of what you were wanting to use the event for?

mjauvin commented 3 weeks ago

@LukeTowers I created a betterCrop() method that can crop from the different sides & corners of an image and I wanted to use the event for this.

LukeTowers commented 3 weeks ago

@mjauvin so right now you're just using the resize event instead?

mjauvin commented 3 weeks ago

@mjauvin so right now you're just using the resize event instead?

Correct