-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwebp.py
More file actions
30 lines (23 loc) · 884 Bytes
/
webp.py
File metadata and controls
30 lines (23 loc) · 884 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""Do file io - WEBP."""
from __future__ import annotations
from PIL import Image
from layeredimage.io.common import expandLayersToCanvas
from layeredimage.layeredimage import LayeredImage
from layeredimage.layergroup import Layer
## WEBP ##
def openLayer_WEBP(file: str) -> LayeredImage:
"""Open a .webp file into a layered image."""
project = Image.open(file)
projectSize = project.size
layers = []
for index in range(project.n_frames):
project.seek(index)
layers.append(
Layer(name=f"Frame {len(layers) + 1}", image=project.copy(), dimensions=projectSize)
)
project.close()
return LayeredImage(layers, projectSize)
def saveLayer_WEBP(fileName: str, layeredImage: LayeredImage) -> None:
"""Save a layered image as .webp."""
layers = expandLayersToCanvas(layeredImage, "WEBP")
layers[0].save(fileName, duration=200, save_all=True, append_images=layers[1:])