Skip to main content

A fast image resizer

Project description

cykooz.resizer

cykooz.resizer is package with the optimized version of image resizing based on Rust's crate fast_image_resize.

CHANGELOG

Installation

python3 -m pip install cykooz.resizer

Or with automatically installing Pillow:

python3 -m pip install cykooz.resizer[pillow]

Information

Supported pixel types and available optimisations:

Format Description SSE4.1 AVX2 Neon
U8 One u8 component per pixel (e.g. L) + + +
U8x2 Two u8 components per pixel (e.g. LA) + + +
U8x3 Three u8 components per pixel (e.g. RGB) + + +
U8x4 Four u8 components per pixel (e.g. RGBA, RGBx, CMYK) + + +
U16 One u16 components per pixel (e.g. L16) + + +
U16x2 Two u16 components per pixel (e.g. LA16) + + +
U16x3 Three u16 components per pixel (e.g. RGB16) + + +
U16x4 Four u16 components per pixel (e.g. RGBA16, RGBx16, CMYK16) + + +
I32 One i32 component per pixel - - -
F32 One f32 component per pixel + + -
F32x2 Two f32 components per pixel (e.g. LA32F) + + -
F32x3 Three f32 components per pixel (e.g. RGB32F) + + -
F32x4 Four f32 components per pixel (e.g. RGBA32F) + + -

Implemented resize algorithms:

  • Nearest - is nearest-neighbor interpolation, replacing every pixel with the nearest pixel in the output; for upscaling this means multiple pixels of the same color will be present.
  • Convolution with different filters:
    • box
    • bilinear
    • catmull_rom
    • mitchell
    • gaussian
    • lanczos3
  • Super sampling - is resizing an image in two steps. The first step uses the "nearest" algorithm. The second step uses "convolution" with configurable filter.

Usage Examples

Resize Pillow's image

from PIL import Image

from cykooz.resizer import FilterType, ResizeAlg, Resizer, ResizeOptions


resizer = Resizer()
dst_size = (255, 170)
dst_image = Image.new('RGBA', dst_size)

for i in range(1, 10):
    image = Image.open('nasa_%d-4928x3279.png' % i)
    resizer.resize_pil(image, dst_image)
    dst_image.save('nasa_%d-255x170.png' % i)

# Resize using a bilinear filter and ignoring an alpha channel.
image = Image.open('nasa-4928x3279.png')
resizer.resize_pil(
    image,
    dst_image,
    ResizeOptions(
        resize_alg=ResizeAlg.convolution(FilterType.bilinear),
        use_alpha=False,
    )
)

Resize raw image with an alpha channel

from cykooz.resizer import ImageData, PixelType, Resizer


def resize_raw(width: int, height: int, pixels: bytes):
    src_image = ImageData(
        width,
        height,
        PixelType.U8x4,
        pixels,
    )
    resizer = Resizer()
    dst_image = ImageData(255, 170, PixelType.U8x4)
    # By default, Resizer multiplies and divides by alpha channel
    # images with `U8x2`, `U8x4`, `U16x2` and `U16x4` pixels.
    resizer.resize(src_image, dst_image)
    return dst_image

Change used CPU-extensions

from cykooz.resizer import Resizer, CpuExtensions


resizer = Resizer()
resizer.cpu_extensions = CpuExtensions.sse4_1
...

Resize with using thread-pool

from cykooz.resizer import Resizer, ResizeOptions, ResizerThreadPool


...
thread_pool = ResizerThreadPool(num_threads=6)
resizer = Resizer()
resizer.resize(
    src_image,
    dst_image,
    ResizeOptions(thread_pool=thread_pool),
)
...

Benchmarks

Environment:

  • CPU: AMD Ryzen 9 5950X
  • RAM: DDR4 4000 MHz
  • Ubuntu 24.04 (linux 6.8.0)
  • Python 3.12
  • Rust 1.83.0
  • cykooz.resizer = "3.1" (single-threaded mode)

Other Python libraries used to compare of resizing speed:

Resize algorithms:

  • Nearest
  • Convolution with Bilinear filter
  • Convolution with Lanczos3 filter

Resize RGBA image 4928x3279 => 852x567

Package (time in ms) nearest bilinear lanczos3
Pillow 0.89 107.21 203.67
cykooz.resizer 0.20 26.09 50.47
cykooz.resizer - sse4_1 0.20 12.12 24.91
cykooz.resizer - avx2 0.20 8.53 22.10

Resize grayscale (U8) image 4928x3279 => 852x567

  • Source image nasa-4928x3279.png has converted into grayscale image with one byte per pixel.
Package (time in ms) nearest bilinear lanczos3
Pillow 0.23 21.41 51.15
cykooz.resizer 0.17 5.30 12.17
cykooz.resizer - sse4_1 0.17 2.11 5.84
cykooz.resizer - avx2 0.17 1.86 4.58

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cykooz.resizer-3.1.1.tar.gz (27.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

cykooz.resizer-3.1.1-cp313-cp313-win_amd64.whl (2.7 MB view details)

Uploaded CPython 3.13Windows x86-64

cykooz.resizer-3.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

cykooz.resizer-3.1.1-cp313-cp313-macosx_11_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

cykooz.resizer-3.1.1-cp313-cp313-macosx_10_12_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

cykooz.resizer-3.1.1-cp312-cp312-win_amd64.whl (2.7 MB view details)

Uploaded CPython 3.12Windows x86-64

cykooz.resizer-3.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

cykooz.resizer-3.1.1-cp312-cp312-macosx_11_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

cykooz.resizer-3.1.1-cp312-cp312-macosx_10_12_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

cykooz.resizer-3.1.1-cp311-cp311-win_amd64.whl (2.7 MB view details)

Uploaded CPython 3.11Windows x86-64

cykooz.resizer-3.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

cykooz.resizer-3.1.1-cp311-cp311-macosx_11_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

cykooz.resizer-3.1.1-cp311-cp311-macosx_10_12_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

cykooz.resizer-3.1.1-cp310-cp310-win_amd64.whl (2.7 MB view details)

Uploaded CPython 3.10Windows x86-64

cykooz.resizer-3.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

cykooz.resizer-3.1.1-cp310-cp310-macosx_11_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

cykooz.resizer-3.1.1-cp310-cp310-macosx_10_12_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.10macOS 10.12+ x86-64

cykooz.resizer-3.1.1-cp39-cp39-win_amd64.whl (2.7 MB view details)

Uploaded CPython 3.9Windows x86-64

cykooz.resizer-3.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

cykooz.resizer-3.1.1-cp39-cp39-macosx_11_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

cykooz.resizer-3.1.1-cp39-cp39-macosx_10_12_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.9macOS 10.12+ x86-64

File details

Details for the file cykooz.resizer-3.1.1.tar.gz.

File metadata

  • Download URL: cykooz.resizer-3.1.1.tar.gz
  • Upload date:
  • Size: 27.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for cykooz.resizer-3.1.1.tar.gz
Algorithm Hash digest
SHA256 c99130c979ffcbcbc5b114e32d82c06b3544f0ddcd8c80b628befc8853e2f4bf
MD5 46569fa882166aad1a9bdd5cf6f6152b
BLAKE2b-256 2cbd841fc97e51c9f69d8d6960163b07246e2df8bb6190145f2a5ce3279accde

See more details on using hashes here.

File details

Details for the file cykooz.resizer-3.1.1-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-3.1.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 9134c1d33d4dd5e406add5e58e5f533eed95e46ab1147748d300487f73648955
MD5 df57c10f6d0a1f7148651ef220a0721c
BLAKE2b-256 d1ae4d7410382036127f6a916954f898b2897f2801b84053f01994882007e364

See more details on using hashes here.

File details

Details for the file cykooz.resizer-3.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-3.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 934ab7c4a9c0591e37ff787da2368fadc9b347ec36fffdea7511abd90dfa9d4d
MD5 e1d471d2cbf929f14c2d2a398d1178ee
BLAKE2b-256 8454b8bd2623458f487fccca3f20c72ef42be2b8dca656b216f5a821f21869d6

See more details on using hashes here.

File details

Details for the file cykooz.resizer-3.1.1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-3.1.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 aefec9429f0fba70871f3c1336e3cffd0c0e98d3df1db9bdc79bb9bc9db4b860
MD5 970fe17ffe5a480e34de7466bbffe051
BLAKE2b-256 88357546d50c0cd29561a59d226ec0ee6b651fa1f04cfe37fb7fdb6eaa1d2ed6

See more details on using hashes here.

File details

Details for the file cykooz.resizer-3.1.1-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-3.1.1-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 f9e6cad31228076fa3bb6d391c8fc7f496d083b7c5bb33fad64ad30dcbcfd098
MD5 f35e1379889761305a9e7526ec78059e
BLAKE2b-256 c42b2dcd9888201029db0a46eaf29390cfd07bf0cef67f56e24d11be619a0185

See more details on using hashes here.

File details

Details for the file cykooz.resizer-3.1.1-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-3.1.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 d05629db8ba844f413b4b87830027b56c77c83bc774045bccd220210f545f57a
MD5 ce09fd4f5653e2683cddfffc43e79d96
BLAKE2b-256 9c2a1fcd70064ac04460046069347490bb82382e032cfe5fc9bade9e8ae10031

See more details on using hashes here.

File details

Details for the file cykooz.resizer-3.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-3.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 49bb25767e3b446dc7011bc6619c0d46e2d3f2286c617e6afc22b6a95c980afd
MD5 5a5059e4927a0baccb40c5f19455ecd7
BLAKE2b-256 5d49725e5ce3477d96bc17ca00f3e18e94d70d7c463b4a02c45d40ac7178832a

See more details on using hashes here.

File details

Details for the file cykooz.resizer-3.1.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-3.1.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0a9b55e8b07558eaf127e2248324b5385bba2c4757969d488af5bad76be8280e
MD5 fe513be18259f4e688f7816b85786f40
BLAKE2b-256 09bee410e25468ee264cd186b6c08d0d7b1bee49e471f0b7744eb70533f2c6f2

See more details on using hashes here.

File details

Details for the file cykooz.resizer-3.1.1-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-3.1.1-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 7678f3b61c684b5333aa955eda2b2aa486bc1ced7bfc6d919e7edd3d3a7c90e8
MD5 09f8b99019612372787e9ec11a15c801
BLAKE2b-256 ec2f4094de6cf0c999d8e8cfda063c9a353c7a1223db809b71735b77b574469c

See more details on using hashes here.

File details

Details for the file cykooz.resizer-3.1.1-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-3.1.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 eb7459f26568f52f881c20fb202436a37184c63fa927385f8d0c4c3f6a7b56a1
MD5 192e9d148f5b64a6c086ed17d73b0bb7
BLAKE2b-256 76ef95034bcd5ecc4b3fc1efb920927bbcd4facd9fcac0e6ade43dc7e332f3c4

See more details on using hashes here.

File details

Details for the file cykooz.resizer-3.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-3.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4f19531a2cf6dc5456895bb39ae4a0f9ce63b4fa663b5142d5f0395ec4c90edc
MD5 706bed99325fd31206cee8c1e0829b56
BLAKE2b-256 40d889b60e7377bb4bdc749aec15d885e2066c4d55d33fe73c32952abecf0e5d

See more details on using hashes here.

File details

Details for the file cykooz.resizer-3.1.1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-3.1.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 efd4e92cf031ed2ecff7f98a38974542b918e48963971e7dde9836dc8389bbce
MD5 8c110a87e918964e66f52a2d7b921237
BLAKE2b-256 c37a89287841977c1b6bcce5a717d9f57ba99326d33b934e3d21cd3ee75fe9da

See more details on using hashes here.

File details

Details for the file cykooz.resizer-3.1.1-cp311-cp311-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-3.1.1-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 d81d65ce568a1ad2775f057898ebce2d7ba05b1d340743876bf3433900956b91
MD5 b140b0d925c395d8d92df698bb1becad
BLAKE2b-256 caa28f59fea46032437d8e7bdb2cb2c8dd34cdd736a63b8d7151fa2cce73615b

See more details on using hashes here.

File details

Details for the file cykooz.resizer-3.1.1-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-3.1.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 a03db77c86faa9a9459e16120a5eb6e505e53cb5573072defb7ec8849445f488
MD5 9782f6a2e2676808477ca2d5deb355a1
BLAKE2b-256 905c16677dda480340154a60251d1c9903c956db6f16d714f45127e3ca571928

See more details on using hashes here.

File details

Details for the file cykooz.resizer-3.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-3.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 98aaf4b1cc537268e51b3c7b1ad21a2e8b70f177638c9f614ee6c12282863496
MD5 c27cfde254339971ea98bc8d29696ec8
BLAKE2b-256 ee7edccf13580546bba008d1b4b7202ba94cdf0347e320446bbc4e5cac8b0db7

See more details on using hashes here.

File details

Details for the file cykooz.resizer-3.1.1-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-3.1.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 61b377612d9990658d45e51985c4c05092369445e39f03a89086f98433f7c878
MD5 3b021a16043974a0b1aa308a7c04d11d
BLAKE2b-256 a60b74620c45246b2f53c4f482bec237b0cae0d8af02efca7ff4e85435e37517

See more details on using hashes here.

File details

Details for the file cykooz.resizer-3.1.1-cp310-cp310-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-3.1.1-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 7a5e48e158105b79aecdb866a9d3410be0c806b1c90b733be3d71e61e4a21337
MD5 f67a6b32c3c78338a9578a9d0638f481
BLAKE2b-256 5c6fa44670ff6791ce7e576a3cc6c55146ff6075958f95bd3d0a2655b4207e15

See more details on using hashes here.

File details

Details for the file cykooz.resizer-3.1.1-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-3.1.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 310dc48e219e910f44fa859be98649b8d74a0d4ab508e0414d34f7b79fbf5ed2
MD5 3069399166e0d279f781b0046d06c6f5
BLAKE2b-256 e2f354040b0bb452701915908241707b43d751d1def66aa38f974e4d3dfb3c09

See more details on using hashes here.

File details

Details for the file cykooz.resizer-3.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-3.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3f64191b024f55bff02660a00cfe63032e3aba0f0690ba2b1e9d299021b8893f
MD5 21fd2df145a52349ad0e1f7ccc2a5065
BLAKE2b-256 3755116e5a52b4016099653d3556eb6bb89f0066f7a1a9ebd0a84ec6bb828b38

See more details on using hashes here.

File details

Details for the file cykooz.resizer-3.1.1-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-3.1.1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 10a7d6fa73c7110f1d30c4b04979a4c89310ac56b2ecb5f65a7f1371f1d1f7b5
MD5 32ad3afed2eef557e38de692f280c73d
BLAKE2b-256 b9063c5a7812d3221bd0c9304ff69b6fef9be7f15b314bd192afcba9611e8bcf

See more details on using hashes here.

File details

Details for the file cykooz.resizer-3.1.1-cp39-cp39-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-3.1.1-cp39-cp39-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 75c005a71466f4481913b1303b8202b10bfd8457a22127c5d72f8529764e2dda
MD5 2de1db0ce43e1fdfd41cc7a35844df83
BLAKE2b-256 ca8ac559e15c39b7d0be0242fd75ec7fd10f9cdc65784c0d02e95a5abacb53e7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page