Skip to content

Reader: Add saliency detection for smart cropping#25451

Open
kean wants to merge 3 commits intotrunkfrom
fix/image-crop-feed
Open

Reader: Add saliency detection for smart cropping#25451
kean wants to merge 3 commits intotrunkfrom
fix/image-crop-feed

Conversation

@kean
Copy link
Copy Markdown
Contributor

@kean kean commented Mar 25, 2026

@kean kean added this to the 26.9 milestone Mar 25, 2026
@kean kean added the Reader label Mar 25, 2026
@kean kean force-pushed the fix/image-crop-feed branch from 79fe6ba to 9b8925a Compare March 25, 2026 20:07
@kean kean force-pushed the fix/image-crop-feed branch from 9b8925a to 7512ee3 Compare March 25, 2026 20:10
@kean kean requested a review from crazytonyli March 25, 2026 20:10
@wpmobilebot
Copy link
Copy Markdown
Contributor

wpmobilebot commented Mar 25, 2026

App Icon📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack
ConfigurationRelease-Alpha
Build Number31794
VersionPR #25451
Bundle IDcom.jetpack.alpha
Commit7242024
Installation URL5pf8mq9ftmiq0
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot
Copy link
Copy Markdown
Contributor

wpmobilebot commented Mar 25, 2026

App Icon📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress
ConfigurationRelease-Alpha
Build Number31794
VersionPR #25451
Bundle IDorg.wordpress.alpha
Commit7242024
Installation URL73uqt90jlbvoo
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@sonarqubecloud
Copy link
Copy Markdown

}

/// Runs saliency detection serially — one image at a time.
private actor SaliencyDetector {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The SaliencyDetector.detect looks like a pure function. Does this type need to be an actor?

// Convert to UIKit coordinates (origin at top-left, Y increases downward).
return CGRect(
x: union.origin.x,
y: 1.0 - union.origin.y - union.height,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What is this 1.0? Should the y be: image.size.height - union.origin.y - union.height?

private static let diskURL: URL = {
let caches = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask)[0]
return caches.appendingPathComponent("saliency_cache.json")
}()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure if it's worth saving the cache to disc. It should not be too bad to recalculate again on the next launch, right? Also, the disk cache will only be usable if the same images appear again in the Reader feed.

/// When `true`, saliency detection only runs for images whose height exceeds their
/// width (portrait images). Landscape and square images are displayed immediately
/// without blocking on detection. Default is `true`.
public var isSaliencyPortraitOnly = true
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nitpick: These two properties can be merged into one property of enum SaliencyDetection { disabled, portraintOnly }

} else {
imageView.isHidden = false
backgroundColor = .clear
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Probably should call self.setNeedsLayout() here to update the imageView.frame?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants