Skip to main content

Generate multi-size ICO favicon files from PNG/JPG images. Pure Python with Pillow.

Project description

dreamega-ico-encoder

Generate .ico favicon files from any image. Multi-size support. Built by Dreamega.

Installation

pip install dreamega-ico-encoder

Usage

Generate ICO from a file

from dreamega_ico_encoder import generate_ico_from_file

# Create favicon with default sizes (16, 32, 48, 64, 128, 256)
generate_ico_from_file("logo.png", "favicon.ico")

# Custom sizes
generate_ico_from_file("logo.png", "favicon.ico", sizes=[16, 32, 48])

Generate ICO from a PIL Image

from PIL import Image
from dreamega_ico_encoder import generate_ico

img = Image.open("logo.png")
ico_bytes = generate_ico(img, sizes=[16, 32, 64, 256])

with open("favicon.ico", "wb") as f:
    f.write(ico_bytes)

Generate ICO from raw bytes

from dreamega_ico_encoder import generate_ico_from_bytes

with open("logo.png", "rb") as f:
    raw = f.read()

ico_bytes = generate_ico_from_bytes(raw, sizes=[16, 32, 48])

with open("favicon.ico", "wb") as f:
    f.write(ico_bytes)

API Reference

generate_ico(source, sizes=None) -> bytes

Generate a multi-size ICO file from a PIL Image.

Parameter Type Default Description
source PIL.Image.Image (required) Input image (any mode, converted to RGBA internally).
sizes list[int] | None [16, 32, 48, 64, 128, 256] Square icon sizes in pixels. Each must be 1-256.

Returns: bytes -- the ICO file content.

generate_ico_from_file(input_path, output_path, sizes=None) -> None

Read an image file and write an ICO file to disk.

Parameter Type Default Description
input_path str (required) Path to source image (PNG, JPG, BMP, etc.).
output_path str (required) Destination path for the ICO file.
sizes list[int] | None [16, 32, 48, 64, 128, 256] Square icon sizes.

generate_ico_from_bytes(image_bytes, sizes=None) -> bytes

Generate ICO from raw image bytes.

Parameter Type Default Description
image_bytes bytes (required) Raw bytes of any Pillow-supported image format.
sizes list[int] | None [16, 32, 48, 64, 128, 256] Square icon sizes.

Returns: bytes -- the ICO file content.

DEFAULT_SIZES

DEFAULT_SIZES = [16, 32, 48, 64, 128, 256]

The default set of icon sizes used when sizes is not specified.

License

MIT -- see LICENSE.

Links

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

dreamega_ico_encoder-1.0.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

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

dreamega_ico_encoder-1.0.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file dreamega_ico_encoder-1.0.0.tar.gz.

File metadata

  • Download URL: dreamega_ico_encoder-1.0.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for dreamega_ico_encoder-1.0.0.tar.gz
Algorithm Hash digest
SHA256 6c5199762f9996e0633fc11f6d44a9c10645437e2167fd76588ea98de936e962
MD5 3d1762a64252c8b258f417c6791d453a
BLAKE2b-256 59761cd0337e4a2495b0e7b290289a6b2834cfe61a08bd6f47b3495bffd0f284

See more details on using hashes here.

File details

Details for the file dreamega_ico_encoder-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for dreamega_ico_encoder-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 53cff7d93e4313ff642775cecce18f47cccb6655c3b1fbe807825fdb5c508254
MD5 7a24f5ad013920c7cdc854f1563b77cb
BLAKE2b-256 195d115ca8f0e3a97a358762418487a66c9e3373e3672f2f8e8badd3f332174f

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