Python Forum
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
a script i want...
#1
a script i want to make real quick because i want to use it. what want is something that will display a picture, given a file that has a (huge ... 8000+) list of image files, and prompt me for input and record that input with the file path to another file. as soon as it gets the input it takes down the image it is for. then it records the info. then it moves on to the next picture in the next file path in the list, displaying that picture and prompting for its input. i have thousands of old family pictures to go through. i expect this will take many hours. but, i am at home all the time so this is feasible.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
Because it's what I know, I'd use pygame to handle the images, and this module lets you type input.

for image_file in list_of_images:
    image = pg.image.load(image_file).convert()
    
    while typing:
        display_screen.blit(image, (x_position, y_position))
        txt_input_module.update() #set typing to "False" when finished typing input.
Reply
#3
pip search didn't find "display_screen". where does that come from? what is the "typing" variable? just a pseudo-object in abstraction code? my original idea was to launch a command as a background process, tracking its process ID, then signal it to quit when the terminal input comes in. how would your way do this? i haven't written any code, yet. i'm hoping to do this next weekend.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#4
The code there was just an example. display_screen would be whatever you name your window.

eg display_screen = pg.display.set_mode((800, 600)) would open a 800 pixel by 600 pixel window.

For images you'll have to have a pygame window. I don't know what you mean background process or process id. I was just thinking you wanted to have python show an image, you type in some information and then it goes to the next.
Reply
#5
(Apr-12-2020, 05:38 AM)Skaperen Wrote: a script i want to make real quick because i want to use it. what want is something that will display a picture
Then why not try to put something together yourself Think
Pillow is a natural first tough when want to display images in Python.

(Apr-12-2020, 05:38 AM)Skaperen Wrote: prompt me for input and record that input with the file path to another file. as soon as it gets the input it takes down the image it is for. then it records the info. then it moves on to the next picture in the next file path in the list
Do you want to also move file(with eg new filename from input) after it has show eg im.show() Pillow,or just write some info about image with also file path info concatenate to it?
Reply
#6
Did write some code to test this,so can post that code.
Use Thread to no block input() when image show and psutil to close the image process.
im.show() will open with default image program that image format is associated when open image in OS.
I do this in Windows,so i need close irfanview process.
Let Pillow decide image format then just pass out if not a image format.
from PIL import Image, UnidentifiedImageError
import os
from threading import Thread
import psutil
import subprocess

img_path = 'G:/div_code/images'
new_path = 'G:/div_code/images_new/'
for img in os.scandir(img_path):
    #print(img.name)
    try:
        im = Image.open(img.name)
        t1 = Thread(target=im.show,)
        t1.start()
        with open('image_info.txt', 'a') as f:
            image_input = input('Info about image: ')
            f.write(f'{image_input}: {img_path}{img.name}\n')
        for pid in psutil.process_iter():
            if pid.name() == 'i_view32.exe':
                subprocess.call(f"TASKKILL /F /IM {pid.name()}")
    except UnidentifiedImageError:
        pass
Output:
# Input λ python img_show.py Info about image: A chess image SUCCESS: The process "i_view32.exe" with PID 63216 has been terminated. Info about image: Picture of donuts SUCCESS: The process "i_view32.exe" with PID 63776 has been terminated. Info about image: A food image SUCCESS: The process "i_view32.exe" with PID 66160 has been terminated. Info about image: A doll SUCCESS: The process "i_view32.exe" with PID 66120 has been terminated. # In image_info.txt A chess image: G:/div_code/imageschess_tom.jpg Picture of donuts: G:/div_code/imagesdonut_4.jpg A food image: G:/div_code/imagesKenzie-Gulley-setup-food.jpg A doll: G:/div_code/imagesluis_lopes-wood_doll.jpg
Reply
#7
(Apr-13-2020, 02:37 PM)snippsat Wrote:
(Apr-12-2020, 05:38 AM)Skaperen Wrote: a script i want to make real quick because i want to use it. what want is something that will display a picture
Then why not try to put something together yourself Think
Pillow is a natural first tough when want to display images in Python.
for some things, i like to survey other ideas, first

(Apr-13-2020, 02:37 PM)snippsat Wrote:
(Apr-12-2020, 05:38 AM)Skaperen Wrote: prompt me for input and record that input with the file path to another file. as soon as it gets the input it takes down the image it is for. then it records the info. then it moves on to the next picture in the next file path in the list
Do you want to also move file(with eg new filename from input) after it has show eg im.show() Pillow,or just write some info about image with also file path info concatenate to it?

i might move the file. but i think it would be better to make some hard links or soft links, instead. i might just append it all
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Forum Jump:

User Panel Messages

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