getkirby / kirby

Kirby's core application folder
https://getkirby.com
Other
1.27k stars 167 forks source link

Cropping acts weird on cross-orientation crops with and without focus #5946

Closed nilsmielke closed 5 months ago

nilsmielke commented 10 months ago

Description

I have some weird cropping issues in beta.3. Am cropping to a landscape format like so:

<img src="<?= $slide->bild()->toFile()->crop(1280, 320)->url() ?>" 
     alt=""
     srcset="<?= $slide->bild()->toFile()->srcset([
                    '400w'  => ['width' => 400, 'height' => 100, 'crop' => true,],
                    '800w'  => ['width' => 800, 'height' => 200, 'crop' => true,],
                    '1200w' => ['width' => 1280, 'height' => 320, 'crop' => true]
                 ]) ?>"
     sizes="(max-width: 1280px) 100vw, 1280px"
>

If the image chosen is a portrait format, that exceeds a certain size (tried with 4000 x 6000), the cropping goes bonkers, producing an extreme portrait format of 437 x 1748 px. Then again I tried a 5462 × 8192 px image, which only acts weird, when a focus point is set, but generates perfectly without one. When focus is set, this image doesn’t seem to be cropped at all. It is named “pexels-cedric-fauntleroy-4266947-1280x320-crop-36-5-65-5.jpg” in the media folder, though.

I have deleted the media folder several times, to make sure. Doesn’t improve the situation. Also tried <?= $slide->bild()->toFile()->crop(1280, 320) ?> instead of the above. Same result.

Landscape images seem to always work as expected.

(This might be related to https://github.com/getkirby/kirby/issues/5855.)

Expected behavior
All images should be cropped to the requested output dimensions.

Setup

Kirby Version
4.0.0-beta.3

System

distantnative commented 10 months ago

@nilsmielke could you please provide an example to work with? E.g. "use this picture with the following command"? That would help a lot

nilsmielke commented 10 months ago

@distantnative Sure thing. In my case it is this image: https://www.pexels.com/de-de/foto/frauen-tablet-arzt-gerat-4266947/ (free download, not sure, if their license would allow for it to be uploaded here) When I upload that into the panel and don’t set the focus, it is cropped alright. As soon, as I set the focus, the (renamed) original image is displayed in the frontend. Name being “pexels-cedric-fauntleroy-4266947-1280x320-crop-53-7-68-2.jpg”, but the image actually being a big as the original (5826 x 8738 px). Frontend code:

<figure class="swiper-slide">
    <img src="<?= $slide->bild()->toFile()->crop(1280, 320)->url() ?>"
         alt=""
         sizes="(max-width: 1280px) 100vw, 1280px"
         srcset="<?= $slide->bild()->toFile()->srcset([
            '400w'  => ['width' => 400, 'height' => 100, 'crop' => true,],
            '800w'  => ['width' => 800, 'height' => 200, 'crop' => true,],
            '1200w' => ['width' => 1280, 'height' => 320, 'crop' => true]
         ]) ?>"     
    >
</figure>

When using a cropped version (e.g. 1:1, 5826 x 5826 px) and focus, everything is working fine again.

Kirby 4.0.0-rc.2

distantnative commented 8 months ago

@nilsmielke one more question: are you using IM or Gd for thumbs?

nilsmielke commented 8 months ago

@distantnative GD by default. But just tried IM with

    'thumbs' => [
        'driver' => 'im',
    ],

in config. Same outcome.

distantnative commented 8 months ago

Tackling this finally, but I am having troubles to reproduce the issue, at least with Gd:

In my template I have

<?= $page->image('test.jpg')->crop(1280, 320) ?>

test.jpg being the image you linked with 5462 × 8192 Pixel.

Without a focus point I get: test-1280x320-crop

With one focus point:

Screenshot 2024-01-16 at 19 07 40

test-1280x320-crop-52-6-29-1

With another one

Screenshot 2024-01-16 at 19 07 56

test-1280x320-crop-55-1-49-2

Each time I get 1280x320 pixels and a focus that seems to match. This is with the current release version. Am I missing any steps that I need to try differently?

github-actions[bot] commented 6 months ago

This issue has been marked as stale because it requires further input but has not seen activity in the past months. This is for us to prioritize issues that are still relevant and actionable. It will be closed if no further activity occurs within the next 15 days. If this issue is still relevant to you, please help us in gathering the necessary input.