Resize
The Resize module provides GPU-accelerated image scaling with multiple interpolation algorithms.
All resize methods return a new image at the target dimensions.
Aspect Ratio Preservation
Specify only width or height to maintain aspect ratio automatically.
Example:
Right-click to download and compare in full size
To force specific dimensions (may distort), specify both width and height.
Interpolation Methods
Nearest Neighbor
Fastest method with no interpolation (blocky results).
Example:
Right-click to download and compare in full size
Use for: Pixel art, quick previews, integer scaling
Quality: Low | Speed: Fastest
Bilinear
Fast linear interpolation (smooth results).
Example:
Right-click to download and compare in full size
Use for: General purpose scaling, real-time applications
Quality: Medium | Speed: Fast
Bicubic
High-quality cubic interpolation.
Example:
Right-click to download and compare in full size
Use for: High-quality upscaling, photography, print materials
Quality: High | Speed: Medium
Lanczos
Highest quality with sharp details (recommended).
Example:
Right-click to download and compare in full size
Use for: Maximum quality upscaling, professional photography
Quality: Highest | Speed: Slower (still fast on GPU)
Parameters
All methods share the same parameters:
src(Image): Source imagewidth(int | None): Target width in pixels (default: None)height(int | None): Target height in pixels (default: None)dst_buffer(Image | None): Optional pre-allocated buffer (default: None)
Note: At least one of width or height must be specified.
Returns: New Image at target size (or None if dst_buffer provided)
Buffer Reuse
For batch processing, reuse the destination buffer. The buffer allows dynamic resizing as long as it has enough capacity.
Example:
from pyimagecuda import Image, load, Resize, save
# Pre-allocate destination with max capacity (e.g., 4K)
dst = Image(3840, 2160)
for file in image_files:
src = load(file)
# dst automatically adjusts its dimensions to the result
# No need to calculate height or resize dst manually
Resize.lanczos(src, width=800, dst_buffer=dst)
save(dst, f"resized_{file}")
src.free()
dst.free()
When using dst_buffer, the buffer's capacity must be large enough to hold the result. The buffer's logical dimensions (width, height) are automatically updated to match the operation result.