Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image (PNG/PDF) support #213

Open
TimothyK opened this issue Jan 7, 2025 · 0 comments
Open

Image (PNG/PDF) support #213

TimothyK opened this issue Jan 7, 2025 · 0 comments

Comments

@TimothyK
Copy link

TimothyK commented Jan 7, 2025

Is your feature request related to a problem? Please describe.
I'd like to take snapshots of image files, namely PNG files.

Describe the solution you'd like
I'd like to be able to match on a System.Drawing.Image object or byte array. Also, be able to easily change the file extension of the snap file to png, or whatever image format I'd like.

Maybe something like myImageByteArray.MatchSnaphot(ImageFormat.Png);

Describe alternatives you've considered
I've tried just taking a snap shot of the byte array of the image. However these are not the same times that get stored to the snap file. Extra formatting is added.

My workaround is just to use the mangled byte array as the snap file and I also write out the PNG file to the snapshot folder too so that developers or any other tool can open the image file.

var snapFilename = Snapshot.FullName();
using (var image = Image.FromStream(new MemoryStream(myImageByteArray)))
{
    var pngFilename = new FileInfo(Path.Combine(snapFilename.FolderPath, "__snapshots__", $"{nameof(MyTestClass)}_{nameof(MyTestMethod)}_as") + ".png");
    image.Save(pngFilename.FullName, ImageFormat.Png);
}

Additional context
My current use case is PNG files. Although, I can see a use case for PDF files too (in order to compare report outputs).

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

No branches or pull requests

1 participant