Handle non image files safely
This commit is contained in:
parent
beb2de46d1
commit
987a99c8a1
|
@ -2,15 +2,18 @@ import os
|
|||
from pathlib import Path
|
||||
from typing import Iterable, Tuple
|
||||
|
||||
from PIL import Image
|
||||
from PIL import Image, UnidentifiedImageError
|
||||
|
||||
|
||||
def scan_directory(directory: Path) -> Iterable[Tuple[Path, Tuple[int, int]]]:
|
||||
for root, _, filenames in os.walk(directory):
|
||||
for filename in [Path(os.path.join(root, fname)) for fname in filenames]:
|
||||
if filename.is_file():
|
||||
image = Image.open(filename)
|
||||
yield (filename, image.size)
|
||||
try:
|
||||
image = Image.open(filename)
|
||||
yield (filename, image.size)
|
||||
except UnidentifiedImageError:
|
||||
continue
|
||||
|
||||
|
||||
def move_wallpaper(wallpaper: Path, target: Path) -> Path:
|
||||
|
|
Loading…
Reference in New Issue