Skip to main content

Extracts a part of the image specified by width and height from the given image file path using OpenCV.

pip install getpartofimg

Tested against Windows 10 / Python 3.10 / Anaconda

Parameters:

image : Any The file path of the image from which a part will be extracted.

width : int The desired width of the extracted part.

height : int The desired height of the extracted part.

allow_resize : bool, optional (default=True) If True, allows resizing of the input image when the specified width or height is greater than the original image's dimensions.

Returns:

numpy.ndarray The extracted part of the image as a NumPy array.

Raises:

ValueError If the 'allow_resize' parameter is set to False and the specified width or height is greater than the original image's dimensions, a ValueError is raised with a message indicating that the image is too small.

Notes:

The function uses the 'cv2.imread_plus' function ( https://github.com/hansalemaos/a_cv_imwrite_imread_plus ) to read the image from the given file path. It then calculates the possible ranges for extracting the desired part based on the image's dimensions and the specified width and height. If the 'allow_resize' parameter is True, the function resizes the image using 'cv2.easy_resize_image' ( https://github.com/hansalemaos/a_cv2_easy_resize ) with the 'cv2.INTER_AREA' interpolation method to fit the desired part. Otherwise, it raises a ValueError.

Random starting coordinates within the allowable range are generated to extract the part of the image specified by the given width and height.

# Example usage:
import cv2
from getpartofimg import get_part_of_image
im = get_part_of_image(image=r"https://raw.githubusercontent.com/hansalemaos/screenshots/main/pic5.png", width=600, height=500, allow_resize=True)
cv2.imwrite('c:\\testimage.png', im)

Metadata

Release files for getpartofimg 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 getpartofimg 0.10
File Size Uploaded Provenance Actions
getpartofimg-0.10.tar.gz 49.7 kB Without provenance Details for getpartofimg-0.10.tar.gz

Built distribution (wheel)

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

Total release size: 100.6 kB

Release files / getpartofimg-0.10.tar.gz

Download URL getpartofimg-0.10.tar.gz
Size 49.7 kB
Tags Source
SHA-256 checksum
How to use checksums
fdf6e590b0bd67994b478d3c58e843c485da3674eb32e1759eda847ab83113b5
BLAKE2b-256 checksum
How to use checksums
30dac0bb7334099a407c85b0befd644496a045418ec7d41114bfc43cfecf212b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.10

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

Download URL getpartofimg-0.10-py3-none-any.whl
Size 50.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4d5c32f6d1c5b78274cd4a3efa8a9daf63d1bd40a9ed2692d37b17e56f8e21e3
BLAKE2b-256 checksum
How to use checksums
9df814536520c673d6cbddd81badd3af3670d5573b5cd00e68cbb5e7cefe04c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.10

Security for getpartofimg 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