From 5d3440815d7616bf3af37ca68136a73d610f071a Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Mon, 15 Apr 2024 16:33:15 +0100 Subject: [PATCH] Pushing non-invasive photos to app wip --- .../photos/README.md | 0 .../photos/app.py | 28 +++++++++++-------- .../photos/requirements.txt | 0 3 files changed, 16 insertions(+), 12 deletions(-) rename etl/{non_invasive_surveys => non_intrusive_surveys}/photos/README.md (100%) rename etl/{non_invasive_surveys => non_intrusive_surveys}/photos/app.py (84%) rename etl/{non_invasive_surveys => non_intrusive_surveys}/photos/requirements.txt (100%) diff --git a/etl/non_invasive_surveys/photos/README.md b/etl/non_intrusive_surveys/photos/README.md similarity index 100% rename from etl/non_invasive_surveys/photos/README.md rename to etl/non_intrusive_surveys/photos/README.md diff --git a/etl/non_invasive_surveys/photos/app.py b/etl/non_intrusive_surveys/photos/app.py similarity index 84% rename from etl/non_invasive_surveys/photos/app.py rename to etl/non_intrusive_surveys/photos/app.py index ffd993a6..c531355b 100644 --- a/etl/non_invasive_surveys/photos/app.py +++ b/etl/non_intrusive_surveys/photos/app.py @@ -5,7 +5,7 @@ from pathlib import Path from dotenv import load_dotenv # Inputs -ENV_FILEPATH = "etl/non_invasive_surveys/photos/.env" +ENV_FILEPATH = "etl/non_intrusive_surveys/photos/.env" PHOTO_DIRECTORY = "/Users/khalimconn-kowlessar/Downloads/IMMO - Dudley Pilot - non-invasive raw data" FOLDER_UPRN_LOOKUP = { "91 Osprey Drive DY1 2JS": 90048026, @@ -55,25 +55,29 @@ def list_files_in_directory(directory_path, file_extension=".jpg"): def create_images(input_path, uprn): + # Define the base directory path + base_directory = f"non_intrusive_photos/{uprn}" + print(f"Creating directory: {base_directory}") # Debug: print the directory to be created + # Need to create local directory if it doesn't exist - os.makedirs(f"non_invasive_photos/{uprn}", exist_ok=True) + os.makedirs(base_directory, exist_ok=True) + + # Define output paths + thumbnail_path = os.path.join(base_directory, "thumbnail.jpg") + full_hd_path = os.path.join(base_directory, "1080p.jpg") + webp_path = os.path.join(base_directory, "webp.webp") # Save as WebP format # Load the image with Image.open(input_path) as img: - # Define output paths - thumbnail_path = f"non_invasive_photos/{uprn}/thumbnail.jpg" - full_hd_path = f"non_invasive_photos/{uprn}/1080p.jpg" - webp_path = f"non_invasive_photos/{uprn}/webp.webp" # Save as WebP format - # Create a thumbnail thumbnail = img.copy() - thumbnail.thumbnail((128, 128), Image.Resampling.LANCZOS) # High-quality downsampling - thumbnail.save(thumbnail_path, 'JPEG', quality=85) # Save as JPEG with quality setting + thumbnail.thumbnail((128, 128), Image.Resampling.LANCZOS) + thumbnail.save(thumbnail_path, 'JPEG', quality=85) # Create a 1080p version full_hd = img.copy() full_hd.thumbnail((1920, 1080), Image.Resampling.LANCZOS) - full_hd.save(full_hd_path, 'JPEG', quality=90) # Slightly higher quality for larger image + full_hd.save(full_hd_path, 'JPEG', quality=90) # Convert to WebP for better compression webp = img.copy() @@ -102,10 +106,10 @@ def generate_cdn_url(distribution_domain, object_name): def process_and_upload_images(uprn, input_image_path, bucket_name, distribution_domain): # Create images - thumbnail, full_hd, original = create_images(str(uprn), input_image_path) + thumbnail, full_hd, original = create_images(input_image_path, uprn=str(uprn)) # Upload images - upload_photos_to_s3(bucket_name, [thumbnail, full_hd, original]) + upload_photos_to_s3(bucket_name, photo_paths=[thumbnail, full_hd, original]) # Generate CDN links cdn_links = [generate_cdn_url(distribution_domain, path.split('/')[-1]) for path in [thumbnail, full_hd, original]] diff --git a/etl/non_invasive_surveys/photos/requirements.txt b/etl/non_intrusive_surveys/photos/requirements.txt similarity index 100% rename from etl/non_invasive_surveys/photos/requirements.txt rename to etl/non_intrusive_surveys/photos/requirements.txt