feat: store original EXIF-stripped image for debugging

- Save original image before crop/rotation with '_debug_original' variant
- Store original_photo_path in labels_data.image_processing for debug access
- Update DebugRotationPanel to display original image instead of processed
- Update ItemDetailModal to pass original image path to debug panel
- Enables accurate crop/rotation visualization with true original image
This commit is contained in:
2026-04-22 11:13:09 +03:00
parent 9f65d427a0
commit c46c8414b8
3 changed files with 57 additions and 2 deletions

View File

@@ -594,6 +594,23 @@ def _auto_save_photo_from_extraction(
# All validation passed, proceed with processing
try:
# Save original image (EXIF-stripped, unprocessed) for debugging
category = db_item.category or "items"
existing_files = []
cat_dir = Path("images") / category.lower()
if cat_dir.exists():
existing_files = [f.name for f in cat_dir.iterdir() if f.is_file()]
filename_base = db_item.name or f"item_{item_id}"
debug_filename = get_unique_filename(filename_base, category, existing_files, variant="debug_original")
try:
original_debug_path = save_image(image_bytes, category, debug_filename.replace("_debug_original.jpg", ""), variant="debug_original")
log.info(f"[AUTO_SAVE] Saved original image for debugging: {original_debug_path}")
except Exception as e:
log.warning(f"[AUTO_SAVE] Failed to save debug original image: {e}")
original_debug_path = None
# Process image (crop + rotation + compression + thumbnail)
processor = ImageProcessor()
log.info(f"[AUTO_SAVE] Processing photo: crop_bounds={crop_bounds_validated}, rotation_degrees={rotation_degrees or 0}")
@@ -664,6 +681,26 @@ def _auto_save_photo_from_extraction(
db_item.photo_thumbnail_path = thumbnail_path
db_item.photo_upload_date = datetime.now(timezone.utc)
# Store image processing metadata in labels_data (including original debug image path)
if not db_item.labels_data:
db_item.labels_data = "{}"
try:
labels = json.loads(db_item.labels_data)
except (json.JSONDecodeError, TypeError):
labels = {}
if "image_processing" not in labels:
labels["image_processing"] = {}
# Add the original image path for debugging
labels["image_processing"]["original_photo_path"] = original_debug_path
labels["image_processing"]["crop_bounds"] = crop_bounds_validated
labels["image_processing"]["rotation_degrees"] = rotation_degrees or 0
db_item.labels_data = json.dumps(labels)
log.info(f"[AUTO_SAVE] Updated labels_data with original_photo_path: {original_debug_path}")
db.commit()
db.refresh(db_item)