Skip to main content

Parallelized image resizing function using OpenCV and multiprocessing

pip install multicv2resize

Tested against Python 3.11 / Windows 10

Parallelized image resizing function using OpenCV and multiprocessing.

This function utilizes the `multiprocnomain` library for parallelizing the resizing process of a batch of images.
The resizing parameters for each image in the batch are specified in a list of dictionaries,
allowing for flexibility in resizing options.

Parameters:
	- pics (list): A list of dictionaries, each containing the following keys:
		- 'img' (Any): Accepts almost any image format
		- 'width' (int, optional): The target width of the resized image. If None, the original width is maintained. - IMPORTANT: (pass either width, height, width and height, or percentage)
		- 'height' (int, optional): The target height of the resized image. If None, the original height is maintained. - IMPORTANT: (pass either width, height, width and height, or percentage)
		- 'percent' (int, optional): The percentage by which to scale the image.  - IMPORTANT: (pass either width, height, width and height, or percentage)
		- 'interpolation' (int, optional): The interpolation method to use during resizing.
		  Defaults to cv2.INTER_AREA.

	- processes (int, optional): The number of parallel processes to use for resizing. Defaults to 5.

	- chunks (int, optional): The number of chunks to divide the resizing tasks into for better load balancing. Defaults to 1.

	- print_stderr (bool, optional): If True, prints stderr messages during the resizing process. Defaults to True.

	- print_stdout (bool, optional): If True, prints stdout messages during the resizing process. Defaults to False.

Returns:
	- dict: A dictionary containing resized images corresponding to the input batch. The keys are generated based on the input image paths.

Example:

	pics0 = [{'img':r"C:\Users\hansc\Pictures\cgea.png",'width':None,'height':None,'percent':percentage,'interpolation':cv2.INTER_AREA} for percentage in range(50,150,1)]
	pics1 = [{'img':r"C:\Users\hansc\Pictures\cgea.png",'width':100+addwidth,'height':100,'percent':None,'interpolation':cv2.INTER_AREA} for addwidth in range(50,150,1)]
	pics=pics0+pics1

	pic=resize_image(pics,processes=5,chunks=1,print_stderr=True, print_stdout=False)
	for k, v in pic.items():
		cv2.imwrite(rf'C:\resi\{k}.png', v)

Metadata

Release files for multicv2resize 0.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for multicv2resize 0.10
File Size Uploaded Provenance Actions
multicv2resize-0.10.tar.gz 56.1 kB Without provenance Details for multicv2resize-0.10.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for multicv2resize 0.10
File Interpreter ABI Platform Actions
multicv2resize-0.10-py3-none-any.whl Python 3 none any Details for multicv2resize-0.10-py3-none-any.whl

Total release size: 113.5 kB

Release files / multicv2resize-0.10.tar.gz

Download URL multicv2resize-0.10.tar.gz
Size 56.1 kB
Tags Source
SHA-256 checksum
How to use checksums
0a973c2443fdb45b34c58053cf6fec44a831551572e224e7f763cf0c9dc9db51
BLAKE2b-256 checksum
How to use checksums
933534eb347bef93d1a6c54a63005052474b918538f04109f208d20d2a461c95
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / multicv2resize-0.10-py3-none-any.whl

Download URL multicv2resize-0.10-py3-none-any.whl
Size 57.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
49563ab3719ce4f7462763063f39fd918a7e1c5149ddc7a99b71f471bb1219bd
BLAKE2b-256 checksum
How to use checksums
f0eeba6cd269ca9b3af87e991890778d21a68af42f543a77e8f9815fdff20f90
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Security for multicv2resize 0.10

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.10 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page