Skip to content

Added type hints to :mod:.utils.images #2194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions manim/utils/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@
__all__ = ["get_full_raster_image_path", "drag_pixels", "invert_image"]


from typing import List

import numpy as np
from PIL import Image

from .. import config
from ..utils.file_ops import seek_full_path_from_defaults


def get_full_raster_image_path(image_file_name):
def get_full_raster_image_path(image_file_name: str) -> str:
return seek_full_path_from_defaults(
image_file_name,
default_dir=config.get_dir("assets_dir"),
extensions=[".jpg", ".jpeg", ".png", ".gif", ".ico"],
)


def drag_pixels(frames):
def drag_pixels(frames: List[np.array]) -> List[np.array]:
curr = frames[0]
new_frames = []
for frame in frames:
Expand All @@ -27,7 +29,7 @@ def drag_pixels(frames):
return new_frames


def invert_image(image):
def invert_image(image: np.array) -> Image:
arr = np.array(image)
arr = (255 * np.ones(arr.shape)).astype(arr.dtype) - arr
return Image.fromarray(arr)