mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
84 lines
2.4 KiB
Python
84 lines
2.4 KiB
Python
from PIL import Image
|
|
|
|
import avalon.io
|
|
from avalon.tvpaint.lib import execute_george
|
|
|
|
|
|
def composite_images(input_image_paths, output_filepath):
|
|
"""Composite images in order from passed list.
|
|
|
|
Raises:
|
|
ValueError: When entered list is empty.
|
|
"""
|
|
if not input_image_paths:
|
|
raise ValueError("Nothing to composite.")
|
|
|
|
img_obj = None
|
|
for image_filepath in input_image_paths:
|
|
_img_obj = Image.open(image_filepath)
|
|
if img_obj is None:
|
|
img_obj = _img_obj
|
|
else:
|
|
img_obj.alpha_composite(_img_obj)
|
|
img_obj.save(output_filepath)
|
|
|
|
|
|
def set_context_settings(asset_doc=None):
|
|
"""Set workfile settings by asset document data.
|
|
|
|
Change fps, resolution and frame start/end.
|
|
"""
|
|
if asset_doc is None:
|
|
# Use current session asset if not passed
|
|
asset_doc = avalon.io.find_one({
|
|
"type": "asset",
|
|
"name": avalon.io.Session["AVALON_ASSET"]
|
|
})
|
|
|
|
project_doc = avalon.io.find_one({"type": "project"})
|
|
|
|
framerate = asset_doc["data"].get("fps")
|
|
if framerate is None:
|
|
framerate = project_doc["data"].get("fps")
|
|
|
|
if framerate is not None:
|
|
execute_george(
|
|
"tv_framerate {} \"timestretch\"".format(framerate)
|
|
)
|
|
else:
|
|
print("Framerate was not found!")
|
|
|
|
width_key = "resolutionWidth"
|
|
height_key = "resolutionHeight"
|
|
|
|
width = asset_doc["data"].get(width_key)
|
|
height = asset_doc["data"].get(height_key)
|
|
if width is None or height is None:
|
|
width = project_doc["data"].get(width_key)
|
|
height = project_doc["data"].get(height_key)
|
|
|
|
if width is None or height is None:
|
|
print("Resolution was not found!")
|
|
else:
|
|
execute_george("tv_resizepage {} {} 0".format(width, height))
|
|
|
|
frame_start = asset_doc["data"].get("frameStart")
|
|
frame_end = asset_doc["data"].get("frameEnd")
|
|
|
|
if frame_start is None or frame_end is None:
|
|
print("Frame range was not found!")
|
|
return
|
|
|
|
handles = asset_doc["data"].get("handles") or 0
|
|
handle_start = asset_doc["data"].get("handleStart")
|
|
handle_end = asset_doc["data"].get("handleEnd")
|
|
|
|
if handle_start is None or handle_end is None:
|
|
handle_start = handles
|
|
handle_end = handles
|
|
|
|
frame_start -= int(handle_start)
|
|
frame_end += int(handle_end)
|
|
|
|
execute_george("tv_markin {} set".format(frame_start - 1))
|
|
execute_george("tv_markout {} set".format(frame_end - 1))
|