@@ -15,7 +15,7 @@ For further reference: https://github.com/hhtznr/pyvideothumbnailer/wiki
1515
1616@Author : Harald Hetzner
1717@License : BSD 3-Clause License
18- @Version : 1.1.2
18+ @Version : 1.1.3
1919"""
2020
2121from __future__ import annotations
@@ -241,6 +241,20 @@ def format_bit_rate(bits_per_second: int) -> str:
241241 """
242242 return '{} kb/s' .format (int (round (bits_per_second / 1000.0 , 0 )))
243243
244+ def get_font_height (text : str , font : ImageFont .ImageFont ) -> int :
245+ """
246+ Determine the height of a text using a specific font.
247+
248+ Parameters:
249+ text (str): Text to render.
250+ font (ImageFont.ImageFont): Font to use for rendering the text.
251+
252+ Returns:
253+ int: The height of the given text using the font.
254+ """
255+ bbox = font .getbbox (text )
256+ return int (bbox [3 ] - bbox [1 ]) + 1
257+
244258def create_preview_thumbnails (params : PyVideoThumbnailerParameters , file_path : str ) -> None :
245259 """
246260 Create preview thumbnails of a video file.
@@ -433,13 +447,13 @@ def create_preview_thumbnails(params: PyVideoThumbnailerParameters, file_path: s
433447 header_font = ImageFont .truetype (font = params .header_font_name , size = params .header_font_size )
434448
435449 # Height of the header texts
436- text_height_file_info = int ( header_font . getlength ( file_info ) )
437- text_height_size_info = int ( header_font . getlength ( size_info ) )
438- text_height_video_info = int ( header_font . getlength ( video_info ) )
439- text_height_audio_info = int ( header_font . getlength ( audio_info ) )
450+ text_height_file_info = get_font_height ( file_info , header_font )
451+ text_height_size_info = get_font_height ( size_info , header_font )
452+ text_height_video_info = get_font_height ( video_info , header_font )
453+ text_height_audio_info = get_font_height ( audio_info , header_font )
440454 text_height_comment = 0
441455 if comment is not None :
442- text_height_comment = int ( header_font . getlength ( comment ) )
456+ text_height_comment = get_font_height ( comment , header_font )
443457
444458 # Compute the height of the header
445459 header_height = y_spacing
@@ -495,7 +509,7 @@ def create_preview_thumbnails(params: PyVideoThumbnailerParameters, file_path: s
495509 else :
496510 timestamp_font = ImageFont .truetype (font = params .timestamp_font_name , size = params .timestamp_font_size )
497511 x_spacing_timestamp = 2
498- y_spacing_timestamp = 2
512+ y_spacing_timestamp = 3
499513 timestamp_shadow_offset = 1
500514
501515 # Video time at which to capture the next preview
@@ -527,9 +541,8 @@ def create_preview_thumbnails(params: PyVideoThumbnailerParameters, file_path: s
527541
528542 # Add a human-readable timestamp to the preview thumbnail
529543 formatted_time = format_time (time )
530- timestamp_size = timestamp_font .getbbox (formatted_time )
531- timestamp_width = int (timestamp_size [0 ])
532- timestamp_height = int (timestamp_size [1 ])
544+ timestamp_width = timestamp_font .getlength (formatted_time )
545+ timestamp_height = get_font_height (formatted_time , timestamp_font )
533546 x_timestamp = x + thumbnail_width - timestamp_width - x_spacing_timestamp
534547 y_timestamp = y + thumbnail_height - timestamp_height - y_spacing_timestamp - timestamp_shadow_offset
535548 timestamp_position = (x_timestamp , y_timestamp )
0 commit comments