Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Mass load images
#1
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.
Reply
#2
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to do a mass replace within a CSV file? cubangt 9 5,196 May-09-2022, 06:52 PM
Last Post: snippsat
  So, a mass of errors trying to run a zipline-dependant program on 3.5 env Evalias123 2 2,348 Jan-21-2021, 02:22 AM
Last Post: Evalias123
  Kera how to load a dataset of images stored to my computer, not the Cifar-10? hobbyist 5 2,752 Jun-12-2020, 09:31 PM
Last Post: Yoriz
  Change of mass hexa data kosteloos 0 1,718 Aug-12-2019, 10:04 AM
Last Post: kosteloos
  mass rename files in folders kerzol81 5 9,002 Dec-29-2017, 09:08 PM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020