Resizing goes wrong with large portrait foto

Using kirby 3.9.6 , php 8.1.13 using this snippet to resize a single image.

<?php if($image = $block->image()->toFile()): ?>
<figure>
<img 
    src="<?= $image->resize(720, NULL, 90)->url() ?>"
    sizes= "100vw"
    srcset="<?=
        $image->srcset([
        '480w' => [
            'width' => 480,
            'height' => NULL,
        ],
        '600w' => [
            'width' => 600,
            'height' => NULL,
        ],
        '720w' => [
            'width' => 720,
            'height' => NULL,
        ]
        ]);
    ?>"
    >
</figure>
<?php endif ?>

I’m noticing both on local and on a staging server that large portrait photographs (3000+ px wide) aren’t being resized but cropped and skewed instead.
Any suggestions what’s going on? Not enough memory? (1GB on both)
Compare resized


to original

With the original image resized to 1280 and 1600 wide and then uploaded the resize goes through correctly.

could you please post the result of:

<?php if($image = $block->image()->toFile()): ?>
<?php dump($image->exif()) ?>
<?php endif ?>

Maybe there is something wrong in the exif data. There have been issues in the past with some images getting treated as portrait when they are actually landscape and vice versa.

Are you using GD or ImageMagick?

See here Exif orientation tag related issues and how to solve them · Issue #2695 · getkirby/kirby · GitHub

I’m using whatever is the default for resizing. Exif data as follows:

Kirby\Image\Exif Object
(
    [camera] => Kirby\Image\Camera Object
        (
            [make] => Apple
            [model] => iPhone SE
        )

    [location] => Kirby\Image\Location Object
        (
            [lat] => 50.918247222222
            [lng] => 4.4215166666667
        )

    [timestamp] => 1534419975
    [exposure] => 1/126
    [aperture] => f/2.2
    [iso] => 25
    [focalLength] => 83/20
    [isColor] => 1
)

Oh i thought the orientation would be in there too… ok try this one

<?php if($image = $block->image()->toFile()): ?>
<?php dump($image->orientation()) ?>
<?php endif ?>

The default is GD. Is that upto date?

GD is enabled at at version 2.3.0.
Output is:

Kirby\Image\Exif Object
(
    [camera] => Kirby\Image\Camera Object
        (
            [make] => Apple
            [model] => iPhone SE
        )

    [location] => Kirby\Image\Location Object
        (
            [lat] => 50.918247222222
            [lng] => 4.4215166666667
        )

    [timestamp] => 1534419975
    [exposure] => 1/126
    [aperture] => f/2.2
    [iso] => 25
    [focalLength] => 83/20
    [isColor] => 1
)


landscape

The ones I resized in photoshop and then uploaded report the right “portrait” format.

Thanks for that… there we are then, kirby beleives the source image to be landscape, not portrait.

Yes, Photoshop would have reset the orientation flag when you did that. I think what has happened is the iPhone has incourrectly set it when the picture was taken.

1 Like