0% found this document useful (0 votes)
12 views4 pages

Python Script to Organize Images

Uploaded by

shivay thakur
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views4 pages

Python Script to Organize Images

Uploaded by

shivay thakur
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

You said:

creat a python program for automation of the pictures collected from many sources

ChatGPT said:

Here’s a simple and safe Python example to automate organizing pictures collected from
many sources.
This script can:

✔ Scan a folder for images


✔ Detect image types
✔ Automatically sort them by file type or date created
✔ Create organized folders

No restricted content is involved, so it's fine for you to use.

✅Python Automation Script: Organize


Pictures
This program sorts images by file type and year/month they were created.

python
Copy code
import os import shutil from datetime import datetime SOURCE_FOLDER =
r"C:\Users\YourName\Pictures\Unsorted" # change this DEST_FOLDER =
r"C:\Users\YourName\Pictures\Organized" # change this IMAGE_EXTENSIONS =
[".jpg", ".jpeg", ".png", ".gif", ".bmp", ".tiff"] def organize_images(): #
Create destination folder if not exists if not [Link](DEST_FOLDER):
[Link](DEST_FOLDER) # Loop through files in source folder for filename
in [Link](SOURCE_FOLDER): file_path = [Link](SOURCE_FOLDER,
filename) # Skip if not a file if not [Link](file_path): continue #
Check if it's an image ext = [Link](filename)[1].lower() if ext not
in IMAGE_EXTENSIONS: continue # Get creation date created_time =
[Link](file_path) date = [Link](created_time) year
= str([Link]) month = [Link]("%B") # e.g. "January" # Create folder
path target_folder = [Link](DEST_FOLDER, year, month) # Make folders if
not exist [Link](target_folder, exist_ok=True) # Move file
[Link](file_path, [Link](target_folder, filename)) print(f"Moved:
{filename} → {target_folder}") print("\n ✔
All images organized
successfully!") if __name__ == "__main__": organize_images()

✅What this script does


�1. Reads all files from your SOURCE_FOLDER

�2. Detects only image formats

�3. Creates folders like:

yaml
Copy code
Organized/
2024/
March/
April/
2023/
December/

� 4. Moves images into the correct folder


Based on when the picture was created.

Want More Features?


I can add any of these:

� Sort by:
• Camera model
• File size
• Resolution
• Face detection
• Duplicate image removal
• Renaming images automatically
• Converting formats (PNG → JPG, etc.)

Just tell me what kind of automation you want!

You said:
sort by cemra mode

ChatGPT said:

Got it — you want to sort pictures by camera model (EXIF data).

Here is an updated Python script that:

✔ Reads each image


✔ Extracts camera model using EXIF metadata
✔ Creates folders for each camera model
✔ Moves images into those folders

✅Python Script: Sort Images by Camera


Model
This script uses Pillow (PIL) to read EXIF metadata.

�Install needed library first:

bash
Copy code
pip install pillow

✅ Full Python Code


python
Copy code
import os import shutil from PIL import Image, ExifTags SOURCE_FOLDER =
r"C:\Users\YourName\Pictures\Unsorted" # change this DEST_FOLDER =
r"C:\Users\YourName\Pictures\ByCamera" # change this IMAGE_EXTENSIONS =
[".jpg", ".jpeg", ".png", ".tiff"] def get_camera_model(path): try: img =
[Link](path) exif = img._getexif() if not exif: return "Unknown_Camera" #
Find EXIF tag for camera model for tag, value in [Link](): if
value == "Model": model_tag = tag break camera_model = [Link](model_tag,
"Unknown_Camera") # Clean folder name return str(camera_model).replace("/",
"_").replace("\\", "_") except: return "Unknown_Camera" def sort_by_camera():
if not [Link](DEST_FOLDER): [Link](DEST_FOLDER) for filename in
[Link](SOURCE_FOLDER): file_path = [Link](SOURCE_FOLDER, filename)
if not [Link](file_path): continue ext =
[Link](filename)[1].lower() if ext not in IMAGE_EXTENSIONS:
continue camera = get_camera_model(file_path) target_folder =
[Link](DEST_FOLDER, camera) [Link](target_folder, exist_ok=True)
[Link](file_path, [Link](target_folder, filename)) print(f"Moved:
{filename} → {target_folder}") print("\n✔ Sorting by camera model complete!")
if __name__ == "__main__": sort_by_camera()

You might also like