Resize image by %

Hello,

Kirby has a neat function to create thumbnails on the fly.

echo thumb($image, array('width' => 300, 'quality' => 80));

Question: is there a way to resize a image by percentage? E.g. i want the image to be 200% of the original image (and a lower quality).
Is this possible?

PS: getting the dimensions beforehand should be possible with $file->dimensions() but a “oneLiner” would be great.

S.

you can use: https://getkirby.com/docs/cheatsheet/file/imagesize

You can calculate the width like this:

<?php echo thumb($image, array('width' => $image->width() * 20/100, 'quality' => 80)); ?>

Looks good.
But does this code have to read the original file every time or does the thumb-function gets the created thumbnail at the second call?

PS: to make the image double sized should the code look like this instead?

<?php echo thumb($image, array('width' => $image->width() *2, 'quality' => 25)); ?>

S.

This won’t work, because you can’t make the image bigger than it is with the thumb method (and it does not makes sense, either).

It makes sense sometimes… here is a use case:

http://silev.org/test/Retina-resize.html

Well, I see that these articles are about using images of double pixel size for retina displays, but I can’t find anything in them that tells you to artificially blow them up. Rather, take a big image and create two different sized versions of it, @1x and @2x, maybe @3x.

There is the $image->scale(0.5) option. Sadly there’s no parameter for the quality.
Maybe it would make sense to add a quality parameter just like with $image->crop(300, 200, 70)?

But it does not store it at the thumbnails folder so it will be recreated at every template view, right?

S.

But if you don’t have a big image you have to blow it up. That does the trick with this method.

S.

No, it is saved to the thumbs folder as well.

You don’t have to blow it up. Just don’t serve a high-res image if you have no high res image to serve in the first place.