hexdropper

Submodules

Package Contents

Functions

read_image(image_path)

Read the input image into a matrix of pixel values.

most_common_rgb(input_array)

Determine the most common RGB values based on an image-derived array.

rgb_to_hex(*args)

Convert RGB color to hexadecimal format.

create_color_image(hex_code[, image_size, output_path])

Create an image with a specific background color and display the hex code.

Attributes

__version__

hexdropper.__version__
hexdropper.read_image(image_path)[source]

Read the input image into a matrix of pixel values.

Parameters:

image_path (string) – File path to the image to read.

Returns:

Matrix of RGB values for each pixel, in order BGR.

Return type:

ndarray(dtype=float, ndim=3)

Examples

>>> read_image('tests/images/test_image.jpg')
[[[213 181   8]
  [213 181   8]
   ...
  [213 181   8]]

[[213 181 8]
[213 181 8]

[213 181 8]]]

hexdropper.most_common_rgb(input_array)[source]

Determine the most common RGB values based on an image-derived array.

The input

Parameters:

input_array (ndarray(dtype=float, ndim=3)) – Array containing data from a cropped image

Returns:

Most common RGB values.

Return type:

tuple

Examples

>>> most_common_rgb(img_arr)
(8, 181, 213)
hexdropper.rgb_to_hex(*args)[source]

Convert RGB color to hexadecimal format.

Parameters:

*args – Variable length argument list. Can either be three integers (r, g, b) or a single tuple with three integers.

Returns:

The hexadecimal color code as a string. The format of the returned string is ‘#RRGGBB’.

Return type:

str

Examples

>>> rgb_to_hex(255, 0, 0)
'FF0000'  # Red color
>>> rgb_to_hex(0, 255, 0)
'00FF00'  # Green color
>>> rgb_to_hex(0, 0, 255)
'0000FF'  # Blue color
hexdropper.create_color_image(hex_code, image_size=(200, 200), output_path=None)[source]

Create an image with a specific background color and display the hex code.

Parameters:
  • hex_code (str) – A hexadecimal color code string (e.g., ‘#FF5733’), without the ‘#’ symbol.

  • image_size (tuple of int, optional) – The size of the image as a (width, height) tuple. Default is (200, 200).

  • output_path (str, optional) – The file path where the image will be saved. If not specified, the image will be saved in the current working directory with a default name.

Returns:

The function saves the created image as a PNG file with the name based on the hex code (e.g., ‘FF5733.png’).

Return type:

None

Examples

>>> create_color_image('#FF5733')
# This will create and save an image with a red background and 'FF5733' text in the center.
>>> create_color_image('#00FF00', (100, 100), '/path/to/save/image.png')
# This will create a 100x100 green background image with '00FF00' text in the center and save it to the specified path.