Resize image by %


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.


you can use:

You can calculate the width like this:

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

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)); ?>


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:

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.

1 Like

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?


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


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

1 Like

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.