22 lines
463 B
Python
22 lines
463 B
Python
import random
|
|
from pathlib import Path
|
|
|
|
from PIL import Image
|
|
|
|
|
|
def random_file_width(base_path: Path):
|
|
random_tile_file = random.choice(list(base_path.glob('*')))
|
|
with Image.open(random_tile_file) as img:
|
|
return img.size[0]
|
|
|
|
|
|
def is_png(file_path):
|
|
"""
|
|
Make sure an image is a valid PNG.
|
|
Raise exeption if could not load image.
|
|
:param file_path:
|
|
:return:
|
|
"""
|
|
img = Image.open(file_path)
|
|
return img.format == 'PNG'
|