Python Forum

Full Version: Mass load images
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am trying to see if it is possible to import images in mass related to a field. Let me explain:

In Microsoft access I have a calculation field with this link to a folder that holds 715 movie poster images: C:\\Users\pe\Pictures\Photos\" & [Title] & ".jpg"

As you can see I can mass load all my pictures to the correct record by using the field "Title".

I have been interested in using Python 3 and Tkinter to build a front end to a SQLite database. Is it possible to bring in all the images in one import from a SQLite database relating to a field in my GUI for those records?

I see many tutorials how to embed or reference one image but not any importing images in mass based on an identifying field. Hope this makes sense. Thank you.
How did the images get into the SQLite3 database?
what does the .schema look like?
What does the GUI look like?
Please explain all in a way the can clearly be understood.
import only loads a library into python, it's not used to load images.
you can however load an entire directory of images into an intermediate list thusly:
This code is untested, but should work. You can change the suffix clause or eliminate it entirely if you have mixed image types
import pathlib
import os

#Anchor CWD to script directory
os.chdir(os.path.abspath(os.path.dirname(__file__)))

# You can change path below, relative paths (from script directory) are OK.
path_to_images = Path('./images')
image_list = []

images = [imagex for imagex in path_to_images.iterdir() if imagex.is_file() and imagex.suffix== '.png']
for image in images:
    with image.open() as fp:
        image_list.append(fp.read)
This creates a list of images. You can modify code to directly load then into tkinter.
Please note that this could get very memory intensive, depending on size of images, so should only be done this way if you have enough memory to hold all images.
Also note that pathlib requires python 3.6 or newer