Thumbnail bug in python simple gallery

By | November 8, 2023

Python simple gallery is pretty neat but there is an issue when generating thumbnails if your photos are named a certain way. The filename is split at the first dot and then .jpg is added to the file name.

My photos are named: 2023-09-24 19.00.43.jpg which means everything after the hour is truncated. ie the thumbnail becomes 2023-09-24 19.jpg

To fix this, change the split to a right split in files_gallery_logic.py located at: lib/python3.10/site-packages/simplegallery/logic/variants

The right split takes the first element of the array from the right. The maxsplit=1 only splits the name on the first occurrence. ie the .jpg will be removed starting from the right hand side and the first element will be the remainder of the file name.


def get_thumbnail_name(thumbnails_path, photo_name):
    """
    Generates the full path to a thumbnail file
    :param thumbnails_path: Path to the folders where the thumbnails will be stored
    :param photo_name: Name of the original photo
    :return: Full path to the thumbnail file
    """
    photo_name_without_extension = os.path.basename(photo_name).split(".")[0]
    return os.path.join(thumbnails_path, photo_name_without_extension + ".jpg")

Change the last 2 lines to:

photo_name_without_extension = os.path.basename(photo_name).rsplit(".", maxsplit=1)[0]
return os.path.join(thumbnails_path, photo_name_without_extension + ".jpg")

Leave a Reply

Your email address will not be published. Required fields are marked *