Skip to main content

A simple image masking tool.

Project description

img-masker

A simple and lightweight Python tool for masking specific colors in images. Supports both local files and remote image URLs. Built on top of Pillow for image processing.

Sample Output

Original Image Masking Sample 1 Masking Sample 2
Original 1.png 2.png

Sample Image: Meoscarada image credit to PokeAPI.

Features

  • Mask (replace) pixels of a specific color or transparency in an image.
  • Supports both local image files and remote image URLs.
  • Customizable mask and background colors.

Installation

You can install img-masker using pip:

pip install img-masker

Requirements

Usage

Basic Example

from img_masker import mask

# Mask all transparent pixels in an image with black, set background to white
masked_img = mask("https://example.com/image.png",)
masked_img.show()

Parameters

  • image_url (str): Path to a local image file or a remote image URL.
  • mask_color (str): Color to use for masked pixels (default: "black"). Accepts any Pillow-compatible color string, e.g., "red", "#FF0000", "transparent".
  • bg_color (str): Color for non-masked pixels (default: "white").
  • filter_color (str): Target color to mask (default: "transparent"). Pixels matching this color will be replaced by mask_color.

Masking a Specific Color

# Mask all pure red pixels with blue, set background to white
masked_img = mask(
    "input.jpg",
    mask_color="blue",
    bg_color="white",
    filter_color="red"
)
masked_img.show()

Masking Transparent Pixels

# Mask all transparent pixels with black, keep others white
masked_img = mask(
    "input.png",
    mask_color="black",
    bg_color="white",
    filter_color="transparent"
)
masked_img.save("masked.png")

License

This project is licensed under the MIT License. See LICENSE for details.

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

img_masker-1.0.2.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

img_masker-1.0.2-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file img_masker-1.0.2.tar.gz.

File metadata

  • Download URL: img_masker-1.0.2.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for img_masker-1.0.2.tar.gz
Algorithm Hash digest
SHA256 bde6412ce591ed053deebb108e91adf931aec6096c471fb249b56615c8b855ad
MD5 90b85f9e9ffa97228cb31f15d2c22bee
BLAKE2b-256 54e79b238659f3d2880f67efcf317fb10ed54fbed5777f30f38bd1885622f04f

See more details on using hashes here.

File details

Details for the file img_masker-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: img_masker-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for img_masker-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f4d8a16e91505bfebbee9d9b7b09a1fe267cb1740c5a98708d5e6af488d636d6
MD5 94c596f69c2c782369aec1a20c819a3f
BLAKE2b-256 23a7e586a15b1804be367749962373b2d644202ca94d9447275abe19b4d716f1

See more details on using hashes here.

Supported by

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