Question: Utilizing what you have learned from this weeks lecture and ImageSearchExample script provided, develop a Python script that accurately identifies digital images. Extract the testimages

Utilizing what you have learned from this weeks lecture and ImageSearchExample script provided, develop a Python script that accurately identifies digital images.

Extract the testimages provided into the Virtual Desktop Environment (in the persistent storage areas)

Develop a script that:

1) Prompts the user for a directory path to search

2) Verify that the path provided exists and is a directory

3) Iterate through each file in that directory and examine it using PIL.

4) Generate a prettytable report of your search results (sample shown here)

'''

Image Search

Example

'''

# Python Standard Library

import os

# 3rd Party Modules

from PIL import Image

from prettytable import PrettyTable

# Psuedo Constants

SCRIPT_NAME = "Week 4 Image Search"

SCRIPT_DATE = "February 8th 2021"

SCRIPT_AUTHOR = "Author: Brandon Holman"

# End of Script Constants

# Files to Process

testFile = input('Directory Path: ')

tbl = PrettyTable(['Image?','File', 'FileSize', 'Ext', 'Format', 'Width', 'Height', 'Type'])

absPath = os.path.abspath(testFile)

ext = os.path.splitext(absPath)[1]

fileSize = '{:,}'.format(os.path.getsize(absPath))

try:

# Try to open as an image

with Image.open(absPath) as im:

# if success, get the details

imStatus = 'YES'

imFormat = im.format

imMode = "?" # hint im.mode

imWidth = "?"

imHeight = "?"

''' Create a table row for each image, and record any extension mis-match alert '''

tbl.add_row([imStatus, absPath, fileSize, ext, imFormat, imWidth, imHeight, imMode])

except:

imStatus = 'NO'

# else, not a valid image

tbl.add_row([imStatus, absPath, fileSize, ext, 'NA', 'NA', 'NA', 'NA'])

tbl.align = 'l'

print()

print(SCRIPT_NAME)

print(SCRIPT_DATE)

print(SCRIPT_AUTHOR)

print()

print(tbl.get_string())

I am trying to get this to iterate through each file in a directory. Instructions included. Python please

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!