Skip to main content

A tool to substitute the main image in memes.

Project description

rememepy

Rememepy is a simple tool to help you replace main images in memes.

from rememepy import Generator
from PIL import Image

gen = Generator()
meme = gen.substitute("meme.jpg", "substitute.jpg")
meme.show()

Features

substitute() Function

The image substitution algorithm uses several adjustable parameters and returns a PIL.Image.Image object.

def substitute(
    source_img_path: str,
    substitute_img_path: str,
    dominant_cluster_amount: int = 3,
    resize_to: tuple | None = None
) -> PIL.Image.Image
  • dominant_cluster_amount: Controls the number of color clusters used to determine the dominant color in the image. Increasing this value can help identify the main image more precisely. If set to 0, the dominant color is assumed to be white.
  • resize_to: Optionally resizes the substitute image to the specified dimensions. If None, the substitute will be stretched to cover the target area.

Validating Substitution Results

Some memes may cover the entire image area or contain multiple images, which can make substitution less accurate. To check whether the substitution was successful, call validate_last_substitution() after substitute(...).

def validate_last_substitution(
    threshold_min: float = 0.1,
    threshold_max: float = 0.9
) -> bool
  • threshold_min: The minimum portion of the image the substitute should cover.
  • threshold_max: The maximum portion of the image the substitute is allowed to cover.

Foolproof Substitution

The substitute_until_valid() method automatically tries different combinations of parameters until a valid substitution is found or all options have been exhausted. If no valid result is found, it returns None.

def substitute_until_valid(
    source_img_path: str,
    substitute_img_path: str,
    cluster_range: tuple = (0, 6)
) -> PIL.Image.Image | None
  • cluster_range: A range of values for dominant_cluster_amount to try. A wider range increases the likelihood of success but also takes more time.

Installing Rememepy and Supported Versions

Rememepy is available on PyPi:

$ python -m pip install rememepy

Rememepy officially supports Python XX.

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

rememepy-0.1.3.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

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

rememepy-0.1.3-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file rememepy-0.1.3.tar.gz.

File metadata

  • Download URL: rememepy-0.1.3.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for rememepy-0.1.3.tar.gz
Algorithm Hash digest
SHA256 e7ee883b29ab5909c9620d71e626dc152b240e3786221864fbd5a10cbbf07bb8
MD5 512447b1d6f232b3542d0bb99ca6118f
BLAKE2b-256 3d379306189db7c30b34e52d370aab3672685c3d6575fba77157e3ac2d19398f

See more details on using hashes here.

File details

Details for the file rememepy-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: rememepy-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for rememepy-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 cb252916e3ebdb8d70b4caaad821f41d864aed86c83a80d3c6fdece7f4e14449
MD5 99c85b5a197a622a4d4f2d64af30736e
BLAKE2b-256 b868be17cbd0363da15eefa51635419cfaffc6ab252ff55ff8eb91e93bfbe0e4

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