Created
June 25, 2023 05:17
-
-
Save HUGHNew/9ae62137baaca5f83a32ada5a9f462be to your computer and use it in GitHub Desktop.
concat screenshots in vertical view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
for Android Termux images concat vertically usage | |
requirements.txt: | |
pillow | |
typer | |
mannul installation | |
typer: pip | |
pillow: | |
1. `pkg install libjpeg-turbo` or `apt install libjpeg-turbo` | |
2. `LDFLAGS="-L/system/lib/" CFLAGS="-I/data/data/com.termux/files/usr/include/" pip install Pillow` | |
if compilation problem occurs in step2, try `LDFLAGS="-L/system/lib64/" CFLAGS="-I/data/data/com.termux/files/usr/include/" pip install Pillow` | |
""" | |
from datetime import datetime | |
from PIL import Image | |
import typer | |
def get_filename(prefix:str="Screenshot", dt_sep="-", d_sep="-", t_sep="-", ext="jpg") -> str: | |
dt = datetime.now() | |
dt_str = dt.strftime(f"%Y{d_sep}%m{d_sep}%d{dt_sep}%H{t_sep}%M{t_sep}%S") | |
return f"{prefix}_{dt_str}.{ext}" | |
def concat_vertical( | |
images_ref:list[str], | |
prefix: str="Screenshot", | |
dt_sep: str="-", | |
d_sep: str="-", | |
t_sep: str="-", | |
ext: str="jpg"): | |
images = [ | |
Image.open(ref) | |
for ref in images_ref | |
] | |
width = images[0].size[0] | |
height = sum([ | |
img.size[1] | |
for img in images | |
]) | |
output = Image.new("RGB", (width, height)) | |
acc_h = 0 | |
for img in images: | |
output.paste(img, (0, acc_h)) | |
acc_h += img.size[1] | |
output.save(get_filename(prefix, dt_sep, d_sep, t_sep, ext)) | |
if __name__ == "__main__": | |
typer.run(concat_vertical) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment