Skip to main content

A fast image resizer

Project description

cykooz.resizer

cykooz.resizer is package with 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:

  • U8 - one byte per pixel:
    • native Rust-code without forced SIMD
    • SSE4.1 (partial)
    • AVX2
  • U8x3 - three u8 components per pixel (e.g. RGB):
    • native Rust-code without forced SIMD
    • SSE4.1 (partial)
    • AVX2
  • U8x4 - four u8 components per pixel (RGBA, RGBx, CMYK and other):
    • native Rust-code without forced SIMD
    • SSE4.1
    • AVX2
  • U16x3 - three u16 components per pixel (e.g. RGB):
    • native Rust-code without forced SIMD
    • SSE4.1
    • AVX2
  • I32 - one signed integer (32 bits) per pixel:
    • native Rust-code without forced SIMD
  • F32 - one float (32 bits) per pixel:
    • native Rust-code without forced SIMD

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
    • lanczos3
  • Super sampling - resizing an image in two steps. First step uses the "nearest" algorithm. Second step uses "convolution" with configurable filter.

Usage Examples

Resize Pillow's image

from PIL import Image

from cykooz.resizer import FilterType, ResizeAlg, Resizer


resizer = Resizer(ResizeAlg.convolution(FilterType.lanczos3))
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 raw image with alpha channel

from cykooz.resizer import AlphaMulDiv, FilterType, ImageData, PixelType, ResizeAlg, Resizer

def resize_raw(width: int, height: int, pixels: bytes):
    src_image = ImageData(
        width,
        height,
        PixelType.U8x4,
        pixels,
    )
    alpha_mul_div = AlphaMulDiv()
    resizer = Resizer(ResizeAlg.convolution(FilterType.lanczos3))
    dst_image = ImageData(255, 170, PixelType.U8x4)
    alpha_mul_div.multiply_alpha_inplace(src_image)
    resizer.resize(src_image, dst_image)
    alpha_mul_div.divide_alpha_inplace(dst_image)    
    return dst_image

Change used CPU-extensions

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


resizer = Resizer(ResizeAlg.convolution(FilterType.lanczos3))
resizer.cpu_extensions = CpuExtensions.sse4_1
...

Benchmarks

Environment:

  • CPU: Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
  • RAM: DDR4 3000 MHz
  • Ubuntu 20.04 (linux 5.13)
  • Python 3.9
  • Rust 1.59.0
  • cykooz.resizer = "2.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.92 112.37 273.12
cykooz.resizer 0.52 64.97 119.94
cykooz.resizer - sse4_1 0.52 23.20 36.92
cykooz.resizer - avx2 0.52 17.27 26.35

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.29 38.30 117.40
cykooz.resizer 0.21 20.36 36.66

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

Uploaded Source

Built Distributions

cykooz.resizer-2.0-pp37-pypy37_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.whl (263.8 kB view details)

Uploaded PyPy manylinux: glibc 2.5+ x86-64

cykooz.resizer-2.0-cp310-none-win_amd64.whl (211.8 kB view details)

Uploaded CPython 3.10 Windows x86-64

cykooz.resizer-2.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.whl (262.6 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.5+ x86-64

cykooz.resizer-2.0-cp310-cp310-macosx_10_7_x86_64.whl (251.6 kB view details)

Uploaded CPython 3.10 macOS 10.7+ x86-64

cykooz.resizer-2.0-cp39-none-win_amd64.whl (211.8 kB view details)

Uploaded CPython 3.9 Windows x86-64

cykooz.resizer-2.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl (262.6 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.5+ x86-64

cykooz.resizer-2.0-cp39-cp39-macosx_10_7_x86_64.whl (251.6 kB view details)

Uploaded CPython 3.9 macOS 10.7+ x86-64

cykooz.resizer-2.0-cp38-none-win_amd64.whl (212.2 kB view details)

Uploaded CPython 3.8 Windows x86-64

cykooz.resizer-2.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl (262.9 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.5+ x86-64

cykooz.resizer-2.0-cp38-cp38-macosx_10_7_x86_64.whl (251.9 kB view details)

Uploaded CPython 3.8 macOS 10.7+ x86-64

cykooz.resizer-2.0-cp37-none-win_amd64.whl (212.2 kB view details)

Uploaded CPython 3.7 Windows x86-64

cykooz.resizer-2.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl (262.9 kB view details)

Uploaded CPython 3.7m manylinux: glibc 2.5+ x86-64

cykooz.resizer-2.0-cp37-cp37m-macosx_10_7_x86_64.whl (251.9 kB view details)

Uploaded CPython 3.7m macOS 10.7+ x86-64

File details

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

File metadata

  • Download URL: cykooz.resizer-2.0.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.5

File hashes

Hashes for cykooz.resizer-2.0.tar.gz
Algorithm Hash digest
SHA256 e6553e0b44ea8876dea66ac9d36d7b1cba1b76a4ef475c5a9b0963c6a8e76a5a
MD5 8c19d8199cc6eb1c5c32bd0c585d55ac
BLAKE2b-256 1a648b559011a1d32be24d23cc18da7df6216ee9741d72d53b4501f6d5cee99f

See more details on using hashes here.

File details

Details for the file cykooz.resizer-2.0-pp37-pypy37_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.whl.

File metadata

  • Download URL: cykooz.resizer-2.0-pp37-pypy37_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.whl
  • Upload date:
  • Size: 263.8 kB
  • Tags: PyPy, manylinux: glibc 2.5+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.5

File hashes

Hashes for cykooz.resizer-2.0-pp37-pypy37_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 7dff16b35033575a7dbd8bd91d2c2c377742f109609388a7a83911968e5753a8
MD5 123dc4389fe3e4062d40b57146ffc2dc
BLAKE2b-256 84e131142e1f4044275684fdd4204077db7fe1ffe67b0a0454c28f95433ab6ef

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cykooz.resizer-2.0-cp310-none-win_amd64.whl
  • Upload date:
  • Size: 211.8 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.5

File hashes

Hashes for cykooz.resizer-2.0-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 1693aad78bc1cf68cdfe59809cd008bc037043bd2dd26658ed870dcdd504eba6
MD5 ec241a0b9b8cca571e74adc055c7930c
BLAKE2b-256 6e8e528a46ccae40869cd56ad61266d70934e6464c97e56a4607e4761b2e95bb

See more details on using hashes here.

File details

Details for the file cykooz.resizer-2.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.whl.

File metadata

  • Download URL: cykooz.resizer-2.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.whl
  • Upload date:
  • Size: 262.6 kB
  • Tags: CPython 3.10, manylinux: glibc 2.5+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.5

File hashes

Hashes for cykooz.resizer-2.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 92be735249582b823bb9ae5a8cfa5a1335b8a7f539d363f32db64e69098d605b
MD5 956967c3d2778255c8c3a3be2e149a0a
BLAKE2b-256 d1bbae0f596781816db4321ecd79c190a15f2ddf107d435b471d8276243a02d6

See more details on using hashes here.

File details

Details for the file cykooz.resizer-2.0-cp310-cp310-macosx_10_7_x86_64.whl.

File metadata

  • Download URL: cykooz.resizer-2.0-cp310-cp310-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 251.6 kB
  • Tags: CPython 3.10, macOS 10.7+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.5

File hashes

Hashes for cykooz.resizer-2.0-cp310-cp310-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 e58f0e20fc3b1da9e7b1fc5fc0597aadaec63f93261c6feca6c9f7f0a08fdc70
MD5 601e40a8e43e46afd11418e1af31789b
BLAKE2b-256 052f222c89ec1e4718b37361e95b3de616ee3336d59dca5465f7b05637463f60

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cykooz.resizer-2.0-cp39-none-win_amd64.whl
  • Upload date:
  • Size: 211.8 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.5

File hashes

Hashes for cykooz.resizer-2.0-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 5cbccc688629385fdb064eaf8bcffcad2bdf303d1a49d97aa1149162b6fe5a8e
MD5 57fc062331aea0031502dc676bbb8b83
BLAKE2b-256 dc3eb737ecb3f6f8993b132a51cc5592791ddbf70dad70cfa3334e06c82d7a25

See more details on using hashes here.

File details

Details for the file cykooz.resizer-2.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl.

File metadata

  • Download URL: cykooz.resizer-2.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl
  • Upload date:
  • Size: 262.6 kB
  • Tags: CPython 3.9, manylinux: glibc 2.5+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.5

File hashes

Hashes for cykooz.resizer-2.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 bf70547f28ce86bfcfd6a25d2629b6a9c9a7effb919337eef0e2ff0fc1888db8
MD5 d43b9b22a4692f6bc0d682746cceb743
BLAKE2b-256 bd655eec873fe0124339c911bf130d28351d9f37732fff7b449d075659608547

See more details on using hashes here.

File details

Details for the file cykooz.resizer-2.0-cp39-cp39-macosx_10_7_x86_64.whl.

File metadata

  • Download URL: cykooz.resizer-2.0-cp39-cp39-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 251.6 kB
  • Tags: CPython 3.9, macOS 10.7+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.5

File hashes

Hashes for cykooz.resizer-2.0-cp39-cp39-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 5f46f75f8f97492c83c8579c218032ec149cbfe349c907182ed72fb1b20b1074
MD5 9dda3a7fbb88fc913c839f23819701e7
BLAKE2b-256 d238a1c795ea485efd3e8b66ac7e4815fcfecdbc4dc111f8fbfcdce94735732c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cykooz.resizer-2.0-cp38-none-win_amd64.whl
  • Upload date:
  • Size: 212.2 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.5

File hashes

Hashes for cykooz.resizer-2.0-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 4b8e4f9600e6ab1ce090aa7a718416984a64f92a4f84266e4949e3d33f4f4e0c
MD5 bda2fdbc77dcabb5c25552d9a4047f0d
BLAKE2b-256 48bd855d310956b9aef1bd38f711472743c59e86aec8d43c283fb6d456404a71

See more details on using hashes here.

File details

Details for the file cykooz.resizer-2.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl.

File metadata

  • Download URL: cykooz.resizer-2.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl
  • Upload date:
  • Size: 262.9 kB
  • Tags: CPython 3.8, manylinux: glibc 2.5+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.5

File hashes

Hashes for cykooz.resizer-2.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 aee32364cab255095ee14a871bac7c770e0722629a4a53e05244845f6257b76d
MD5 4764ba443337df2c4c3b2e05e6d57629
BLAKE2b-256 b5d0d9ab63c7654713822e3db0fc4842cea2b9959a000ce1e8e030d5b4578bf8

See more details on using hashes here.

File details

Details for the file cykooz.resizer-2.0-cp38-cp38-macosx_10_7_x86_64.whl.

File metadata

  • Download URL: cykooz.resizer-2.0-cp38-cp38-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 251.9 kB
  • Tags: CPython 3.8, macOS 10.7+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.5

File hashes

Hashes for cykooz.resizer-2.0-cp38-cp38-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 e84c7e3d8fb10ee021607eba767d2b41fa3906ad099f7363ae9406b85284285a
MD5 725fbcd87c2b8b378c76cddf69be8283
BLAKE2b-256 12f159bc5fd601853c48ded791f5ab0dc104b273ac286570b69ebe0cb0b963ae

See more details on using hashes here.

File details

Details for the file cykooz.resizer-2.0-cp37-none-win_amd64.whl.

File metadata

  • Download URL: cykooz.resizer-2.0-cp37-none-win_amd64.whl
  • Upload date:
  • Size: 212.2 kB
  • Tags: CPython 3.7, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.5

File hashes

Hashes for cykooz.resizer-2.0-cp37-none-win_amd64.whl
Algorithm Hash digest
SHA256 39f6861092f11885079b3777e75c40216d683d8818ba9bea409d57604b5b9d0a
MD5 369a739e6aa009e0b87b7c159dc1c7b2
BLAKE2b-256 d211ea261a6e8d26935a4f37ab1545c3f62ca166d2950f1c3f2334a5c226daac

See more details on using hashes here.

File details

Details for the file cykooz.resizer-2.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl.

File metadata

  • Download URL: cykooz.resizer-2.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
  • Upload date:
  • Size: 262.9 kB
  • Tags: CPython 3.7m, manylinux: glibc 2.5+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.5

File hashes

Hashes for cykooz.resizer-2.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 7b332897144acf831ed6f3892d2ce18417c68227e376f234acc3fe3712173788
MD5 b8832b264ba9a21646e70bccb2c62dd5
BLAKE2b-256 60d2a5531bfb0ab122292740072b32f3048a32471fe119efb951ec19bb66f628

See more details on using hashes here.

File details

Details for the file cykooz.resizer-2.0-cp37-cp37m-macosx_10_7_x86_64.whl.

File metadata

  • Download URL: cykooz.resizer-2.0-cp37-cp37m-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 251.9 kB
  • Tags: CPython 3.7m, macOS 10.7+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.5

File hashes

Hashes for cykooz.resizer-2.0-cp37-cp37m-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 3052c5db9681980317466d52dcbea59f492831d81ace9d0fd4c2eae32544bfe5
MD5 1b6a582098573d004ab1bcd3a697d82a
BLAKE2b-256 2e3a41193a30a1d53503c0b0d85d3333a386492d8cf584573099e71f7f431b3d

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