Skip to content

EgorKhabarov/RunningTextGifGenerator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GIF generator with a running text line

Tests Code coverage Status

Code style: black mypy checked Linting: Ruff


git clone https://github.com/EgorKhabarov/RunningTextGifGenerator
pip install -r requirements.txt

git submodule add https://github.com/EgorKhabarov/RunningTextGifGenerator
git submodule update --remote
pip install -r RunningTextGifGenerator/requirements.txt

from gif import GIF
gif = GIF()
gif.add_text_fragment("text", intro=True, outro=True)
gif.save(path="text.gif")

text.gif

You can specify the width and height of the screen. By default, they are GIF(columns=79, rows=9).

The GIF class has the ability to add text, image and gif fragments. Each action has its own method add_text_fragment, add_image_fragment and add_gif_fragment respectively.

Important

When adding a fragment, a generator is created to save memory. This means that when saving a gif, all generators will be empty after traversal.

Examples

You can create simple animations from a picture.
from gif import GIF
gif = GIF(columns=22, rows=24)
gif.add_image_fragment(
    image_path="dino.png",
    direction="up",
    duration=100,
    speed=24,
)
gif.save(path="dino.gif")

dino.png

dino.gif

dino.png dino.gif
You can use context managers and change colors.
from gif import GIF

# color settings for all GIF instances
# GIF.global_color_config["..."]

with GIF(20, 20, save_path="frog_jump.gif") as gif:
    gif.color_config["color_pixel_off_light"] = "#438600"
    gif.color_config["color_pixel_off_dark"] = "#346800"
    gif.color_config["color_pixel_on_light"] = "#B9FF73"
    gif.color_config["color_pixel_on_dark"] = "#6AD500"
    gif.add_image_fragment("frog_jump.png", duration=100, speed=21)

frog_jump.gif

dino.gif

frog_jump.png

dino.png

You can combine different fragments with each other.
It is important that the sizes of the pictures and gifs match the sizes of the main gif.
from gif import GIF
gif = GIF()
gif.add_text_fragment("this is text.gif:")
gif.add_gif_fragment(gif_path="text.gif")
gif.save(path="text_text.gif")

text.gif

text.gif

text_text.gif

readme_content/text_text.gif

Bad Apple on RunningTextGifGenerator

bad_apple.gif

Code
"""
Download zip from https://github.com/Felixoofed/badapple-frames/blob/main/frames.zip
"""

import io
import math
import zipfile

from PIL import Image

from gif import GIF


c = 1.3333333333333333
x = 90
y = math.ceil(x / c)
gif = GIF(columns=x, rows=y)
gif.color_config["color_pixel_off_light"] = "#EFEFEF"
gif.color_config["color_pixel_off_dark"] = "#BFBFBF"
gif.color_config["color_pixel_on_light"] = "#2F2F2F"
gif.color_config["color_pixel_on_dark"] = "#000000"


with zipfile.ZipFile("frames.zip", "r") as zip_ref:
    for i in range(1, 6573, 3):
        filename = f"frames/output_{i:0>4}.jpg"
        with zip_ref.open(filename) as file:
            image = Image.open(io.BytesIO(file.read()))
            gif.add_image_fragment(
                image_path=image.resize((x, y)),
                duration=50,
            )

gif.save(path="bad_apple.gif")

The font can be downloaded here