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

saving file as png saves the contents as jpg #203

Closed
basimc4 opened this issue May 2, 2019 · 11 comments
Closed

saving file as png saves the contents as jpg #203

basimc4 opened this issue May 2, 2019 · 11 comments

Comments

@basimc4
Copy link
Contributor

basimc4 commented May 2, 2019

in coypu v3

when calling SaveScreenshot with filename sample.png, the contents of the file are actual jpg ie the mime type is image/jpg instead of image/png

@basimc4
Copy link
Contributor Author

basimc4 commented May 3, 2019

this method doesn't strip out the leading dot in the file extension. the format will always be Jpeg

    internal static ScreenshotImageFormat GetImageFormat(string fileName)
    {
        var extension = new FileInfo(fileName).Extension.ToLower()
                                              .Replace("jpg", "jpeg");

        ScreenshotImageFormat format;
        if (AreEqual(extension, ScreenshotImageFormat.Bmp))
            format = ScreenshotImageFormat.Bmp;
        else if (AreEqual(extension, ScreenshotImageFormat.Gif))
            format = ScreenshotImageFormat.Gif;
        else if (AreEqual(extension, ScreenshotImageFormat.Jpeg))
            format = ScreenshotImageFormat.Jpeg;
        else if (AreEqual(extension, ScreenshotImageFormat.Png))
            format = ScreenshotImageFormat.Png;
        else if (AreEqual(extension, ScreenshotImageFormat.Bmp))
            format = ScreenshotImageFormat.Bmp;
        else
            format = ScreenshotImageFormat.Jpeg;

        return format;
    }

@basimc4
Copy link
Contributor Author

basimc4 commented May 3, 2019

Hi @joshski @adiel ,
I have a fix for this issue as well as a test case for it. How do i go about submitting it.
Thanks
B

@basimc4
Copy link
Contributor Author

basimc4 commented May 3, 2019

i figured it out . see pull request #204

@obstar
Copy link
Collaborator

obstar commented May 7, 2019

@basimc4 thanks, I will take a look on you PR

@boydpatterson
Copy link

I just wanted to add that WebDriver on .NET Core only supports PNG image format. Since PNG files are being unintentionally saved as JPEG image format, that causes WebDriverException every time. Workaround is to bypass BrowserSession and use native WebDriver ITakesScreenshot functionality.

@obstar
Copy link
Collaborator

obstar commented Jul 17, 2019

@basimc4
sorry, I can't reproduce it your issue, I've added a test for PNG and when debugging - the code in ImageFormatParser.cs works correctly

@berckoi
Copy link

berckoi commented Jul 18, 2019

@obstar can this issue please be reopened? I also just ran into it too.

I'm using Coypu in a .NET Core test suite which only supports PNG files. I have my file extension listed as .png, but am getting the following error:

.NET Core does not support image manipulation, so only Portable Network Graphics (PNG) format is supported

This is just like @basimc4 described.

var filename = "filename.png";
var extension = new FileInfo(fileName).Extension; //This will return .png

Coypu's ImageFormatParse.AreEqual() function is:

private static bool AreEqual(string extension, ScreenshotImageFormat imageFormat) 
{
    return extension.Equals(imageFormat.ToString(),        //This will be ".png"
            StringComparison.InvariantCultureIgnoreCase);  //This will be "png"
}

@obstar
Copy link
Collaborator

obstar commented Jul 18, 2019

@berckoi ok, I will go back to it with proper .net core project

@obstar
Copy link
Collaborator

obstar commented Jul 19, 2019

@berckoi @basimc4
fix released https://github.com/featurist/coypu/releases/tag/3.1.1
Please confirm that fix is working. I couldn't reproduce it locally with separate .net core project.

@obstar obstar added Done and removed InProgress labels Jul 19, 2019
@berckoi
Copy link

berckoi commented Jul 19, 2019

Thanks for the quick turn around @obstar! I updated to Coypu 3.1.1 and can confirm that my screenshots are generating flawlessly!

@obstar
Copy link
Collaborator

obstar commented Jul 19, 2019

@berckoi np

@obstar obstar closed this as completed Jul 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants