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 - - -

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
...

Benchmarks

Environment:

  • CPU: AMD Ryzen 9 5950X
  • RAM: DDR4 4000 MHz
  • Ubuntu 22.04 (linux 6.5.0)
  • Python 3.10
  • Rust 1.78.0
  • cykooz.resizer = "3.0"

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.93 104.77 191.08
cykooz.resizer 0.20 28.50 56.33
cykooz.resizer - sse4_1 0.20 12.28 24.31
cykooz.resizer - avx2 0.20 8.58 21.62

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.25 20.62 51.62
cykooz.resizer 0.18 6.25 13.06
cykooz.resizer - sse4_1 0.18 2.12 5.75
cykooz.resizer - avx2 0.18 1.96 4.41

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.0.0.tar.gz (22.1 kB view details)

Uploaded Source

Built Distributions

cykooz.resizer-3.0.0-cp312-none-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.12 Windows x86-64

cykooz.resizer-3.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

cykooz.resizer-3.0.0-cp312-cp312-macosx_11_0_arm64.whl (953.4 kB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

cykooz.resizer-3.0.0-cp312-cp312-macosx_10_12_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.12 macOS 10.12+ x86-64

cykooz.resizer-3.0.0-cp311-none-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.11 Windows x86-64

cykooz.resizer-3.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

cykooz.resizer-3.0.0-cp311-cp311-macosx_11_0_arm64.whl (955.0 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

cykooz.resizer-3.0.0-cp311-cp311-macosx_10_12_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.11 macOS 10.12+ x86-64

cykooz.resizer-3.0.0-cp310-none-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.10 Windows x86-64

cykooz.resizer-3.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

cykooz.resizer-3.0.0-cp310-cp310-macosx_11_0_arm64.whl (954.9 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

cykooz.resizer-3.0.0-cp310-cp310-macosx_10_12_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.10 macOS 10.12+ x86-64

cykooz.resizer-3.0.0-cp39-none-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.9 Windows x86-64

cykooz.resizer-3.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

cykooz.resizer-3.0.0-cp39-cp39-macosx_11_0_arm64.whl (955.4 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

cykooz.resizer-3.0.0-cp39-cp39-macosx_10_12_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.9 macOS 10.12+ x86-64

cykooz.resizer-3.0.0-cp38-none-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.8 Windows x86-64

cykooz.resizer-3.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

cykooz.resizer-3.0.0-cp38-cp38-macosx_11_0_arm64.whl (955.6 kB view details)

Uploaded CPython 3.8 macOS 11.0+ ARM64

cykooz.resizer-3.0.0-cp38-cp38-macosx_10_12_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.8 macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: cykooz.resizer-3.0.0.tar.gz
  • Upload date:
  • Size: 22.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.12

File hashes

Hashes for cykooz.resizer-3.0.0.tar.gz
Algorithm Hash digest
SHA256 d7c46c9ffbf0966efd62bdae05799286190e93b5255eea89bf61a7ca25f5e737
MD5 95bbd9fc04d0399797b37ea872c4f22c
BLAKE2b-256 35a57be3a7b8d98aa0358b4def1eb67e58afe6ddf260e11f364478e60cb6f6a0

See more details on using hashes here.

File details

Details for the file cykooz.resizer-3.0.0-cp312-none-win_amd64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-3.0.0-cp312-none-win_amd64.whl
Algorithm Hash digest
SHA256 838fe65aad9cc14d08eb4b661ef8889e45c0ae2a6663e15bc12760249a520059
MD5 4865b799a7091804b009d3d651b26d28
BLAKE2b-256 c5ab3edc56876bc2feaea4b563140cf40c5011f39050463e1bb5de88401166ab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cykooz.resizer-3.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1d71664efa2e8ab1089c77936ade89e6f9fc157d243011dd079b7c0f8a92c127
MD5 75a794dd67d09cf07dd171fcd0fa9c62
BLAKE2b-256 569e1e312b9314c93bf33039038011d855ef880c4d9bc6885fa0439d7b798c4d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cykooz.resizer-3.0.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 58d3f9de7f84301358957a0e7039a9ca74d35e93c9f2299d929581c466d8f310
MD5 2e6f123020dbee3fa84abeb048a21212
BLAKE2b-256 3f21cb1bfc587f426cd16fe49d8678f42a41f9f0aee241bfb76511aec70a2304

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cykooz.resizer-3.0.0-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 69b1e0690d2d14363ccb5143894d7d816c10bab9791805086b874111a47ae2e3
MD5 a4d2f9da2ea86d8f03752574c803616f
BLAKE2b-256 257dcb103007da80d9f8bb0619533a5b8eb06ffcced0d762966a69184d5e04e7

See more details on using hashes here.

File details

Details for the file cykooz.resizer-3.0.0-cp311-none-win_amd64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-3.0.0-cp311-none-win_amd64.whl
Algorithm Hash digest
SHA256 d2ad05c71451a93275a130542a29cce0dd0f797e8c8e44427df69819d6f59a64
MD5 12b1fbd877143728e9fe515a69807b64
BLAKE2b-256 f1a058d393e0fe2d4a263936ed333666cf3bd0bc91b893e6e18c23811441a993

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cykooz.resizer-3.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 67d71e34ac9c0ec0302ee32dbfeca898005d46a6963666a8241eac6a25944a53
MD5 30da4d10aa1bbcde66795aa9ac33089a
BLAKE2b-256 2b054c3c5c9da1fc8fd2b587920d59bd08b83ad577e2be3715c0bb9d6b08a980

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cykooz.resizer-3.0.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cc566e81a1938cd4e27fb903416804e4d03a0cc0cf9935acb973bb97fbd7880b
MD5 328f66662af7a4ca1bffa6cb98b45e22
BLAKE2b-256 63e6e6bfce91fb66277b77596a1f84f01f384b3097b2c6a44add36de38841f9b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cykooz.resizer-3.0.0-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 363744312db63bf81dfe130047dfa64f270380e2d52ecd6ea4abf520c0933e25
MD5 bd22be7b57372ccd4e3f92a6da7fa430
BLAKE2b-256 b94f5625dd475d4173cf2ccac46d64ccce7021a2788ccd4155daca845281f724

See more details on using hashes here.

File details

Details for the file cykooz.resizer-3.0.0-cp310-none-win_amd64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-3.0.0-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 a6a1a0bba93389311184d09d8b230db8bb936dc7a71f499795c7eab2a9a540f5
MD5 0f9c8863b3b0bdbe9d7c962b51f81048
BLAKE2b-256 fe74406a0165a7c3dc7b7c6880386e177f6a7e037bc4e3015d8d20f58bd105b8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cykooz.resizer-3.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a4fb26db959977a9d2a3f6c41d31dfb69c0dbc248c7713ded55ae388d1de0422
MD5 ee7cfddccea13fe7c51b1ecced190fa6
BLAKE2b-256 7e9f929b8485619c464c38a265c54675af85a227b5aaa31a9750e564adc0f730

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cykooz.resizer-3.0.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8c62903c669f423b8c14122aa806f6a6df08ae137283e79caa346de9119bead1
MD5 72736cf4d77c6757a06cc85a75104736
BLAKE2b-256 8c8f29fa2c3f4f398c318fa33b07d32a50a84251bc799865294a4baaf7593f9c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cykooz.resizer-3.0.0-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 8a53bf7ac938a9d3296f1c2c3c94c37d720a41889a9a16c33ffd7bc260706f4f
MD5 f96bd4aeaeac3490bf606f149f426dc2
BLAKE2b-256 747de3494e57685dfc21ba30741b6e5de4a7ccd1e173bdc72ec183cb67f1f4db

See more details on using hashes here.

File details

Details for the file cykooz.resizer-3.0.0-cp39-none-win_amd64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-3.0.0-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 77590d8362148becf506f64639474114d03d9709d016e62e7188a0fee6a8de07
MD5 370c66250e754ae7a7b62f6bd75acc1f
BLAKE2b-256 981af00a566a25d675544538b86c4a1621194346b0e22a800ae4e47f2d892cc3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cykooz.resizer-3.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9c3bfa8b73b6cc8453240c9d8c0f2f4b028df7b7fce92958b87fe0ccf3954f8b
MD5 97dc7baa12ab073e894b43d968e85e6a
BLAKE2b-256 d890a13b004550b38f7fcf6fc385c028cea2f1d44da9928edc8708dac71c9b31

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cykooz.resizer-3.0.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 10c396115f562eebe1ddcb448137a7e3cb3e28415a773f4b3da87d8a6a8f2009
MD5 d640fb69ae4e6fd4945ad62867171fe1
BLAKE2b-256 afe9a92a6f9918f58b1760586442edddca3e9602bc7a1ec8d7f62b653a1dbd9c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cykooz.resizer-3.0.0-cp39-cp39-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 9cbf88d4631523e8c088726704663efd7eada64ac01ab3dc7fa9ab3cd44991c4
MD5 a99b97d95173782d0d253812d9bd3027
BLAKE2b-256 960268f3dfe41e403b3c0071e9b9d5314c13ec1eec90945f6ff39ed6bbd26538

See more details on using hashes here.

File details

Details for the file cykooz.resizer-3.0.0-cp38-none-win_amd64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-3.0.0-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 6b2c97cc5cb8c173bd0365c212c15c58f28be26ed3dc1d62e25b02b9b4520832
MD5 c9661703ded3c71419e8c23806e88651
BLAKE2b-256 5bad09b73d4ba3e597499ef4485bd41d65537754cd8da1dcb7ab5bb76c4348a4

See more details on using hashes here.

File details

Details for the file cykooz.resizer-3.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-3.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 361020f6e82841e2d088d69fc9a367ff52ff9d19478439fdff17ab7a4d456ba4
MD5 129ffbb9bc91eef0190210c348406f27
BLAKE2b-256 56456a1f8e1521082f9d1e0fd0d9ecb1cf38a08c1d4ce95e2abad412eddf1d29

See more details on using hashes here.

File details

Details for the file cykooz.resizer-3.0.0-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-3.0.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 21fa199ba8a4a79f2634d857755deaf744985636e5624c784ec7f16d39f1c309
MD5 507e5abb6517c7fafc066ae4b838437e
BLAKE2b-256 ee127831fef6cca7e9482ac5abd5240aebf66226ff386fc6dde1deb94030cfc1

See more details on using hashes here.

File details

Details for the file cykooz.resizer-3.0.0-cp38-cp38-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for cykooz.resizer-3.0.0-cp38-cp38-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 d46d3a861280c12fbdddb20ac7e26e33c7aaeb3354954e0bdcba1b259bcf5d55
MD5 1415b0838dc8434ee7fc44e1268a7bf6
BLAKE2b-256 ebfaad207f19451091573bb537c5e7fa8d352e571a8a3b11d5bbeff3c16d9309

See more details on using hashes here.

Supported by

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