Cropping Portrait Images

Hello could someone tell me if my code is wrong; on my gallery loop my code for the actual image is

<img class="thumbnail" src="<?= $file->crop(200, 132)->url() ?>" alt="" />

but this is the output, the portrait images should be cropped to landscape if I’m not mistaken?

the width and the height is swapping on the portrait images, is there a way I can override this and have my width value to only be the width not just the larger value of the two?

Yes, they should. Are the images created at all in the media folder?

It’s cropping them but the width and height are swapping

image

hmmm

something isn’t 100% because

crop(200) gives me this: see first image is not square
image

and crop(200, 200) gives me this;
image

Are the images actually larger that the given sizes?

Yes way larger, they are being uploaded directly from an iphone.

specific request from my client is he wants to manage his website from his iphone

here’s my full loop if relevant;

 <?php foreach ($page->files()->template('image')->sortBy('sort') as $file) : ?>
                    <?php if ($file->type() == 'image') : ?>
                        <div class="col-4 col-xxl-2 mb-3">
                            <a href="<?= $file->url() ?>" alt="<?= $page->title()->html() ?>" class="glightbox">
                                <img class="thumbnail" src="<?= 
                                $file
                                ->crop(200, 200)
                                ->url() ?>" alt="" />
                            </a>
                        </div>
                    <?php endif ?>
                <?php endforeach ?>

I believe it has something to do with the sheer size of the image, my clients iphone is uploading 3.5mb images that are over 3000 x 4000px, if I shrink them down they are completely fine, could there be a PHP.ini setting that I could change that might be stopping the crop feature work at a certain large size?

That’s what I thought. Are you using gd or imagemagick as drivers?

Not sure what I’m using, kirby out of the box settings? never heard of either :grimacing:

I’ve tried adding this to my config file but hasn’t helped, tried with ‘im’ and ‘gd’,

gd is the default, im is more powerful but requires ImageMagick to be available on the server (plus you often have to add the path to the executable in the config).

Since you will probably never need those oversized images, it might make sense to resize them to something useful on upload, e.g. using this plugin: Autoresize | Kirby CMS

1 Like

Plugin worked great, thank you!