MCPcopy Create free account
hub / github.com/LearnPrompt/LearnPrompt / convert_to_webp

Function convert_to_webp

scripts/convert_to_webp.py:12–31  ·  view source on GitHub ↗

Convert image to WebP. Args: source (pathlib.Path): Path to source image Returns: pathlib.Path: path to new image

(source)

Source from the content-addressed store, hash-verified

10image_types = ['.jpg', '.jpeg', '.png', '.bmp', '.tiff']
11
12def convert_to_webp(source):
13 """Convert image to WebP.
14
15 Args:
16 source (pathlib.Path): Path to source image
17
18 Returns:
19 pathlib.Path: path to new image
20 """
21 destination = source.with_suffix(".webp")
22
23 try:
24 image = Image.open(source) # Open image
25
26 image.save(destination, format="webp") # Convert image to webp
27 os.remove(source) # Delete the original image
28
29 return destination
30 except ValueError as e:
31 print(f'Could not convert file {source} due to error: {e}')
32
33def update_paths(file_path):
34 try:

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected