pointfreeco / swift-snapshot-testing

📸 Delightful Swift snapshot testing.
https://www.pointfree.co/episodes/ep41-a-tour-of-snapshot-testing
MIT License
3.67k stars 556 forks source link

Ability to disable alpha channel from image snapshots #761

Open NachoSoto opened 10 months ago

NachoSoto commented 10 months ago

Looks like there is no way to make snapshots opaque? It would save a lot of space to remove the alpha channel when not needed.

CraigSiemens commented 6 months ago

We wanted this as well, though for a different reason https://github.com/pointfreeco/swift-snapshot-testing/issues/673#issuecomment-1854845578

We made a custom Snapshotting instance named opaqueImage that always adds a white background to the image. I'm not sure it reduces the file size, but it's a step closer to being able to do that.

Snapshotting<UIView, UIImage>
    .image(
        size: size,
        traits: traits
    )
    .pullback { view in
        let backgroundView = UIView(frame: view.frame)
        backgroundView.backgroundColor = .white
        backgroundView.preservesSuperviewLayoutMargins = true
        backgroundView.addSubview(view)
        return backgroundView
    }