mirror of
https://github.com/Xevion/simple-viewer.git
synced 2025-12-13 04:13:05 -06:00
add/improve refreshing logic & metadata management, improve thumbnail logic & regenerate kwarg, overall more documentation/commands
This commit is contained in:
@@ -3,6 +3,8 @@ helpers.py
|
||||
|
||||
Contains helper functions used as refactored shortcuts or in order to separate code for readability.
|
||||
"""
|
||||
from typing import Tuple
|
||||
|
||||
import cv2
|
||||
from PIL import Image
|
||||
|
||||
@@ -14,8 +16,8 @@ def generate_thumbnail(path: str, output_path: str) -> None:
|
||||
:param path: The absolute path to the file.
|
||||
:param output_path: The absolute path to the intended output thumbnail file.
|
||||
"""
|
||||
vidcap = cv2.VideoCapture(path)
|
||||
success, image = vidcap.read()
|
||||
file = cv2.VideoCapture(path)
|
||||
success, image = file.read()
|
||||
if success:
|
||||
img = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
||||
im_pil = Image.fromarray(img)
|
||||
@@ -26,3 +28,13 @@ def generate_thumbnail(path: str, output_path: str) -> None:
|
||||
# im_pil.resize((200, 66))
|
||||
|
||||
im_pil.save(output_path)
|
||||
|
||||
|
||||
def get_resolution(path: str) -> Tuple[int, int]:
|
||||
"""
|
||||
Retrieves the resolution of a image or video
|
||||
|
||||
:return: A tuple containing two positive integers representing width and height
|
||||
"""
|
||||
file = cv2.VideoCapture(path)
|
||||
return file.get(cv2.CAP_PROP_FRAME_HEIGHT), file.get(cv2.CAP_PROP_FRAME_WIDTH)
|
||||
|
||||
Reference in New Issue
Block a user