Resize
resize(width, height) returns a new image of the requested size. The image you call it on is not changed.
from pathlib import Path
import libstb as stb
out = Path("out")
out.mkdir(exist_ok=True)
img = stb.Image.open("astronaut.png")
print(f"{img.width}x{img.height}")
# Shrink with the default filter, then enlarge the tiny result with each filter by name.
tiny = img.resize(64, 64)
tiny.write(out / "tiny.png")
print(f"{tiny.width}x{tiny.height}")
for name in ("nearest", "linear", "cubic", "bspline", "mitchell"):
tiny.resize(256, 256, name).write(out / f"{name}.png")
512x512
64x64
The code shrinks astronaut.png to 64×64 with the default filter, then enlarges that small picture to 256×256 once per filter. The small picture is the poorest possible input on purpose, so the differences between filters are easy to see.
What it produces
These pictures are the output of the example above, not separate artwork.






Choosing the filter
The filter is picked by name or by enum. With no filter, libstb uses Catmull-Rom when it enlarges and Mitchell when it shrinks. Names are case-insensitive, and - or a space counts as _.
| Filter | Names |
|---|---|
| default | auto, default |
| nearest | nearest, point |
| linear | linear, bilinear, triangle |
| cubic (Catmull-Rom) | cubic, bicubic, catmull_rom |
| B-spline | bspline, cubic_bspline |
| Mitchell | mitchell |
| box | box, area |
There is no Lanczos filter. An unknown name raises ValueError and lists the valid names.
By default libstb blends pixels in linear light. Resizer(filter, srgb=False) turns that off, which is the like-for-like setting when comparing with libraries that do not do it.
How fast is it
The reference in these two charts is OpenCV, the library that was fastest on the most pictures. On average libstb, with either setting, takes longer than OpenCV here, and less time than Pillow and scikit-image. The note under each chart explains why OpenCV's linear and cubic modes are not a like-for-like comparison when shrinking.
resize, half size, cubic (Catmull-Rom)
- OpenCV1.00× (reference)
- libstb1.81×
- libstb (sRGB-correct)3.56×
- Pillow7.91×
- scikit-image352.1×
libstb, Pillow and scikit-image prefilter when shrinking; OpenCV's INTER_LINEAR and INTER_CUBIC do not (faster, and they alias), and INTER_AREA is its antialiasing counterpart. "libstb" is Resizer(filter, srgb=False), the like-for-like pairing; "libstb (sRGB-correct)" is the library's own default, which blends in linear light like a correct resizer should, listed separately so the price of that is visible. 3-channel images only. scikit-image is skipped above 1 MP (seconds per call).
resize, double size, cubic (Catmull-Rom)
- OpenCV1.00× (reference)
- libstb2.05×
- libstb (sRGB-correct)3.88×
- Pillow7.99×
- scikit-image872.2×
libstb, Pillow and scikit-image prefilter when shrinking; OpenCV's INTER_LINEAR and INTER_CUBIC do not (faster, and they alias), and INTER_AREA is its antialiasing counterpart. "libstb" is Resizer(filter, srgb=False), the like-for-like pairing; "libstb (sRGB-correct)" is the library's own default, which blends in linear light like a correct resizer should, listed separately so the price of that is visible. 3-channel images only. scikit-image is skipped above 1 MP (seconds per call).
Time of each library divided by the time of the reference (lower is better), averaged over the pictures of the corpus (18 compared per operation). Log scale. Measured 2026-10-15 11:24 UTC, 7 repeats, Intel(R) Xeon(R) Processor, 1 logical core(s). Source: benchmarks/outputs/benchmark.json.
API at a glance
| Open a file | stb.Image.open(path) |
|---|---|
| Resize | img.resize(w, h, filter) |
| Write | img.write(path) |
| Pick the filter | a name, or a Resizer.Filter for Resizer; an unknown name raises ValueError |
| Linear-light blending off | stb.Resizer(filter, srgb=False) |