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 to0, the dominant color is assumed to be white.resize_to: Optionally resizes the substitute image to the specified dimensions. IfNone, 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 fordominant_cluster_amountto 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 3.10+.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rememepy-0.1.4.tar.gz.
File metadata
- Download URL: rememepy-0.1.4.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b8605e0d7cff0ac53fb3987800228bd861c11b8d3422730ccd5b189da58212ef
|
|
| MD5 |
914d212937ca25a2aa1e83e6fae52d51
|
|
| BLAKE2b-256 |
4fda4ff76beb875e8aa5706192a401aa6085ffdd1ca5bf74f40e3ab15c83d506
|
File details
Details for the file rememepy-0.1.4-py3-none-any.whl.
File metadata
- Download URL: rememepy-0.1.4-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6bb7a98852f984f827fa9a61b2d208082e3e0bf5cdd97d173460227087bbec57
|
|
| MD5 |
18421dde67ba358f0592591883491af9
|
|
| BLAKE2b-256 |
f827666af898830582a8c978841c521bc2e29bd4013623a59d47b3cfd5faaae5
|