Imagen AI supports a wide range of professional photography file formats. The SDK includes built-in constants for file validation and supports both RAW camera formats and standard JPEG images.
Important: A single project can contain either RAW files or JPEG files, but not both types mixed together. Each file type must be in a separate project.
The SDK provides three constants for file format validation:
from imagen_sdk import ( RAW_EXTENSIONS, # Set of RAW file extensions JPG_EXTENSIONS, # Set of JPEG file extensions SUPPORTED_FILE_FORMATS # All supported formats combined)
from pathlib import Pathfrom imagen_sdk import SUPPORTED_FILE_FORMATSfile_path = Path("photo.cr2")file_ext = file_path.suffix.lower()if file_ext in SUPPORTED_FILE_FORMATS: print(f"✅ {file_ext} is supported")else: print(f"❌ {file_ext} is not supported")
from pathlib import Pathfrom imagen_sdk import RAW_EXTENSIONS, JPG_EXTENSIONSdef validate_file_consistency(file_paths: list[str]) -> tuple[bool, str]: """ Check if all files are the same type (all RAW or all JPEG). Returns (is_valid, message) """ raw_files = [] jpeg_files = [] unsupported_files = [] for path in file_paths: ext = Path(path).suffix.lower() if ext in RAW_EXTENSIONS: raw_files.append(path) elif ext in JPG_EXTENSIONS: jpeg_files.append(path) else: unsupported_files.append(path) # Check for unsupported files if unsupported_files: return False, f"Unsupported files: {unsupported_files}" # Check for mixed types if raw_files and jpeg_files: return False, "Cannot mix RAW and JPEG files in same project" # All valid and consistent if raw_files: return True, f"All {len(raw_files)} files are RAW format" elif jpeg_files: return True, f"All {len(jpeg_files)} files are JPEG format" else: return False, "No files provided"# Example usagefiles = ["photo1.cr2", "photo2.nef", "photo3.dng"]is_valid, message = validate_file_consistency(files)print(f"{is_valid}: {message}")# True: All 3 files are RAW format
from pathlib import Pathfrom imagen_sdk import RAW_EXTENSIONSdef find_raw_files(directory: str) -> list[str]: """Find all RAW files in directory.""" directory_path = Path(directory) raw_files = [] for ext in RAW_EXTENSIONS: # Use glob for each extension raw_files.extend( str(p) for p in directory_path.glob(f"*{ext}") ) return sorted(raw_files)# Usageraw_photos = find_raw_files("./wedding_photos")print(f"Found {len(raw_photos)} RAW files")
from pathlib import Pathfrom imagen_sdk import RAW_EXTENSIONS, JPG_EXTENSIONSdef validate_with_profile(files: list[str], profile_image_type: str) -> bool: """ Validate files match profile image type. profile_image_type: "RAW" or "JPG" """ for file in files: ext = Path(file).suffix.lower() if profile_image_type == "RAW": if ext not in RAW_EXTENSIONS: print(f"❌ {file} is not RAW format") return False elif profile_image_type == "JPG": if ext not in JPG_EXTENSIONS: print(f"❌ {file} is not JPEG format") return False return True# Usageraw_files = ["photo1.cr2", "photo2.nef"]is_valid = validate_with_profile(raw_files, "RAW")print(f"Validation result: {is_valid}")
# ❌ INVALID: RAW profile with JPEG filesprofile.image_type = "RAW"files = ["photo1.jpg", "photo2.jpeg"]# Error: RAW profile cannot be used with JPG files
Solution: Use correct profile type:
# ✅ VALID: Match profile type to filesprofiles = await client.get_profiles()# For RAW files, use RAW profileraw_profile = next(p for p in profiles if p.image_type == "RAW")raw_files = ["photo1.cr2", "photo2.nef"]# For JPEG files, use JPEG profilejpeg_profile = next(p for p in profiles if p.image_type == "JPG")jpeg_files = ["photo1.jpg", "photo2.jpeg"]
import asynciofrom pathlib import Pathfrom imagen_sdk import ( ImagenClient, get_profiles, RAW_EXTENSIONS, JPG_EXTENSIONS, SUPPORTED_FILE_FORMATS)async def process_directory(directory: str): """Process all supported files in a directory.""" # 1. Find all supported files dir_path = Path(directory) raw_files = [] jpeg_files = [] for file in dir_path.iterdir(): if file.is_file(): ext = file.suffix.lower() if ext in RAW_EXTENSIONS: raw_files.append(str(file)) elif ext in JPG_EXTENSIONS: jpeg_files.append(str(file)) print(f"Found {len(raw_files)} RAW and {len(jpeg_files)} JPEG files") # 2. Get profiles profiles = await get_profiles("your_api_key") raw_profile = next((p for p in profiles if p.image_type == "RAW"), None) jpeg_profile = next((p for p in profiles if p.image_type == "JPG"), None) async with ImagenClient("your_api_key") as client: # 3. Process RAW files if any if raw_files and raw_profile: print(f"Processing {len(raw_files)} RAW files...") raw_project = await client.create_project("RAW_Batch") await client.upload_images(raw_project, raw_files) await client.start_editing(raw_project, raw_profile.profile_key) raw_links = await client.get_download_links(raw_project) await client.download_files(raw_links, "output/raw") print("✅ RAW files processed") # 4. Process JPEG files if any if jpeg_files and jpeg_profile: print(f"Processing {len(jpeg_files)} JPEG files...") jpeg_project = await client.create_project("JPEG_Batch") await client.upload_images(jpeg_project, jpeg_files) await client.start_editing(jpeg_project, jpeg_profile.profile_key) jpeg_links = await client.get_download_links(jpeg_project) await client.download_files(jpeg_links, "output/jpeg") print("✅ JPEG files processed")asyncio.run(process_directory("./photos"))