mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
Pushing non-invasive photos to app wip
This commit is contained in:
parent
d3a1754683
commit
5d3440815d
3 changed files with 16 additions and 12 deletions
|
|
@ -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]]
|
||||
Loading…
Add table
Reference in a new issue