Skip to content

Conversation

@StephenMcConnel
Copy link
Contributor

@StephenMcConnel StephenMcConnel commented Jan 29, 2026


Open with Devin

This change is Reviewable

@greptile-apps
Copy link

greptile-apps bot commented Jan 29, 2026

Greptile Overview

Greptile Summary

Fixed overcropping bug that occurred when the same image file was used multiple times with different crop settings.

Key Changes:

  • Added srcUsageCount dictionary to track how many times each image file is referenced in the document
  • Modified the logic for determining when a new filename is needed for cropped images
  • Previously only checked if there were uncropped instances of an image (uncroppedSrcNames.Contains(src))
  • Now also checks if an image is used more than once (srcUsageCount[src] > 1)

Problem Solved:
When an image file was used multiple times with different crops, the second crop operation would inadvertently crop the already-cropped result, causing progressive overcropping. By tracking usage count, the fix ensures each cropping operation gets a unique filename when the same source image needs different crops, preventing the second crop from operating on an already-cropped file.

Impact:
This is a focused bug fix with no breaking changes. The existing test suite validates the expected behavior for various scenarios including uncropped images, images with same crops, and images with different crops.

Important Files Changed

Filename Overview
src/BloomExe/ImageProcessing/ImageUtils.cs Added srcUsageCount dictionary to prevent overcropping when same image file is used multiple times with different crops

Sequence Diagram

sequenceDiagram
    participant Caller
    participant ReallyCropImages
    participant Dict as Dictionaries
    participant ReallyCropImage
    participant MakeCroppedImage
    
    Caller->>ReallyCropImages: bookDom, imageSourceFolder, imageDestFolder
    
    Note over ReallyCropImages,Dict: First pass: Analyze all images
    ReallyCropImages->>Dict: Initialize uncroppedSrcNames (HashSet)
    ReallyCropImages->>Dict: Initialize cropped (Dictionary)
    ReallyCropImages->>Dict: Initialize srcUsageCount (Dictionary)
    
    loop For each img element
        ReallyCropImages->>ReallyCropImages: Get src attribute
        alt Image is not cropped
            ReallyCropImages->>Dict: Add src to uncroppedSrcNames
        end
        ReallyCropImages->>Dict: Increment srcUsageCount[src]
    end
    
    Note over ReallyCropImages,MakeCroppedImage: Second pass: Process cropping
    loop For each img element with cropping
        ReallyCropImages->>ReallyCropImages: Get src, style, canvas dimensions
        ReallyCropImages->>ReallyCropImages: Create key from src|style|dimensions
        
        alt Key exists in cropped dict
            ReallyCropImages->>ReallyCropImages: Reuse existing cropped filename
        else Key not in cropped dict
            ReallyCropImages->>ReallyCropImages: Calculate needNewName
            Note right of ReallyCropImages: needNewName = uncroppedSrcNames.Contains(src)<br/>|| srcUsageCount[src] > 1
            ReallyCropImages->>ReallyCropImage: Process image with needNewName flag
            ReallyCropImage->>MakeCroppedImage: Create cropped version
            MakeCroppedImage-->>ReallyCropImage: croppedImagePath
            alt needNewName is true
                ReallyCropImage->>ReallyCropImage: Use new GUID-based filename
            else needNewName is false
                ReallyCropImage->>ReallyCropImage: Overwrite original file
            end
            ReallyCropImage-->>ReallyCropImages: croppedFileName
            ReallyCropImages->>Dict: Store croppedFileName in cropped[key]
        end
    end
    
    ReallyCropImages-->>Caller: Processing complete
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

Copy link

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional flags.

Open in Devin Review

@StephenMcConnel StephenMcConnel force-pushed the BL-15772-PublishedImagesOvercropped branch from 4010ad3 to 09136b9 Compare January 29, 2026 23:13
@StephenMcConnel StephenMcConnel force-pushed the BL-15772-PublishedImagesOvercropped branch from 09136b9 to a0c19bd Compare January 30, 2026 00:17
@hatton hatton merged commit 2491bfc into Version6.3 Jan 30, 2026
1 check passed
@hatton hatton deleted the BL-15772-PublishedImagesOvercropped branch January 30, 2026 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants