Replies: 3 comments 13 replies
-
|
I think this is a great idea 😃 . I would definitely prefer it to be implemented in an additional package, and I'm always happy to welcome new contributors. The current API should be improved a little for this:
Would you like to work on a PR for these changes to inline-snapshot, or would you just like to implement the plugin? |
Beta Was this translation helpful? Give feedback.
-
|
We should also change how |
Beta Was this translation helpful? Give feedback.
-
|
I think there might also be an usability problem. Lets say you have code like this: def test_1():
assert create_image1() == external("phash:1238abe.png")
def test_2():
assert create_image2() == external("phash:1238abe.png")and both create_image function return similar images but not the same and the result of create_image2 is never saved because it is similar to create_image1. You are not able to watch the diff to the last run when the result of create_image2 changes. You only see the diff to the result of create_image1. Maybe this is exactly what is wanted when you use this, maybe not. I don't know. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey Frank 👋
I'm working with a program that generates images, and I'd like to verify outputs remain consistent by comparing perceptual hashes (fast, compact) while keeping the actual image files archived for manual inspection when needed.
Current approach
I'm using
czkawkato generate perceptual hashes of image outputs:This works - the perceptual hashes are compact (e.g.,
"8LS0tOSwvLQ"), suitable for inline snapshots, and allow for similarity comparison unlike cryptographic hashes.What I'm trying to achieve
I'd like something like:
where inline-snapshot would:
8LS0tOSwvLQ.png)Why both hash and file?
My program does page dewarping optimization, which is slow. On test runs, I want to compare against the hash string without loading images. When a test fails or output changes, I need the original image available for visual comparison to understand what regressed.
The hash serves as a proxy for the expected output while the archived file provides the reference for investigation.
Proposed implementation: new storage protocol
Looking at how
hash:works (storing files based on content hash), I think aphash:protocol would fit naturally:How it would work
assert output_path == external("phash:")assert output_path == external("phash:8LS0tOSwvLQ.png")On subsequent test runs:
8LS0tOSwvLQfrom the snapshot stringThe archived image serves as reference for manual inspection when outputs change.
Implementation approach
Since protocols determine where/how files are named (
hash:,uuid:) while formats determine how data is serialized (.txt,.json,.bin), this fits the protocol pattern. I need custom naming logic based on perceptual hash, but standard image storage.I'm thinking it’d be best to implement this as a storage protocol similar to
HashStorage, computing perceptual hashes instead of SHA256. The main question is whether this belongs in inline-snapshot core or as a third-party extension - I'll start with a standalone implementation and we can discuss integration if it proves generally useful.One alternative would be parameterizing
HashStorageto accept different hash functions, but I think that would complicate the implementation without much benefit since perceptual hashing has specific requirements (image inputs, tolerance handling eventually).I'm planning to start with a third-party extension (e.g.,
inline-snapshot-phash) since:If it starts looking broadly useful, I'd love to contribute to inline-snapshot proper☺️
Beta Was this translation helpful? Give feedback.
All reactions