uber / ios-snapshot-test-case

Snapshot view unit tests for iOS
MIT License
1.79k stars 211 forks source link

Issues with snapshots containing "complicated" transparent images #120

Open mime29 opened 4 years ago

mime29 commented 4 years ago

In a project I'm working on, we have lots of issues with "glitches" in captures images when the transparent images contain shadows or text with rounded fonts.

It results in image comparison failure and diff images with those "glitches" that are very small differences.

I made a fix that seems to solve the issue using swizzling so far. I can't make a PR on the concerned files on this repository at this point because it might impact other projects using this library. If anybody has an idea how we can make it configurable, that would be good.

The fix:

In + (UIImage *)fb_imageForLayer:(CALayer *)layer and + (UIImage *)fb_imageForView:(UIView *)view from the file UIImage+Snapshot.m I changed the context to capture only opaque images by changing the following line:

from

UIGraphicsBeginImageContextWithOptions(bounds.size, NO, 0); 

to

UIGraphicsBeginImageContextWithOptions(bounds.size, YES, 0);

Note: I went in OpenRadar to try to find a bug related to this but didn't find any screenshot glitches posts. As this issue could maybe come from some compression algorithm that I'm not aware of, I'm not filing a radar yet.

zablaetna commented 4 years ago

I've been noticing this a lot lately, too. Image Diffs that look completely blank.

tinder-maxwellelliott commented 3 years ago

In a project I'm working on, we have lots of issues with "glitches" in captures images when the transparent images contain shadows or text with rounded fonts.

It results in image comparison failure and diff images with those "glitches" that are very small differences.

I made a fix that seems to solve the issue using swizzling so far. I can't make a PR on the concerned files on this repository at this point because it might impact other projects using this library. If anybody has an idea how we can make it configurable, that would be good.

The fix:

In + (UIImage *)fb_imageForLayer:(CALayer *)layer and + (UIImage *)fb_imageForView:(UIView *)view from the file UIImage+Snapshot.m I changed the context to capture only opaque images by changing the following line:

from

UIGraphicsBeginImageContextWithOptions(bounds.size, NO, 0); 

to

UIGraphicsBeginImageContextWithOptions(bounds.size, YES, 0);

Note: I went in OpenRadar to try to find a bug related to this but didn't find any screenshot glitches posts. As this issue could maybe come from some compression algorithm that I'm not aware of, I'm not filing a radar yet.

Can you simply share a patch file of the necessary changes?