Resize both width and height
I wish to resize an image overriding the aspect ratio. I couldn't find a way to do this.
Is there a way to directly give the required size overriding the aspect ratio?
Thanks!
Hi @AntixK ,
If it's in a file, the easiest way is with thumbnail:
x = pyvips.Image.thumbnail("something.jpg", 200, height=300, size="both")
Will size to 200x300 pixels.
If it's an image, use resize and give both an hscale and vscale.
Appreciate the quick response!
I tried the thumbnail method, but it still resizes by the aspect ratio.

Argh, sorry, I should not rely on memory. Try:
$ python3
Python 3.9.7 (default, Sep 10 2021, 14:59:43)
[GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyvips
>>> x = pyvips.Image.thumbnail("k2.jpg", 200, height=300, size="force")
>>> x
<pyvips.Image 200x300 uchar, 3 bands, srgb>
Another related question -
How do I set the interpolation method for resizing the image? According to docs, the default seems to be LANCZOS3.
My goal here is to get a resized image identical to the one I have with PIL. The Lanczos kernel used there seems to be slightly different (Maybe Lanczos2?).
Thank you.
thumbnail picks the best interpolator for you -- it's supposed to do a best practice resize and not give you any options. If you want more control, you need to drop down to a lower level and call reduce directly.
I don't think you can expect identical results. Image resize is complex, with a lot of unspecified parts, and two different implementations are unlikely to handle issues like rounding and centreing in an identical way.