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

Png to Webp with MatteColor will throw Unsupported pixel format exception #165

Open
JasonLiuLiuLiuLiu opened this issue Sep 5, 2024 · 4 comments

Comments

@JasonLiuLiuLiuLiu
Copy link

Prerequisite: A PNG image with alpha transparency.

The code to reproduce this issue:

using System.Drawing;
using PhotoSauce.MagicScaler;
using PhotoSauce.NativeCodecs.Giflib;
using PhotoSauce.NativeCodecs.Libheif;
using PhotoSauce.NativeCodecs.Libjpeg;
using PhotoSauce.NativeCodecs.Libjxl;
using PhotoSauce.NativeCodecs.Libpng;
using PhotoSauce.NativeCodecs.Libwebp;

CodecManager.Configure(codecs =>
{
	codecs.UseGiflib();
	codecs.UseLibheif();
	codecs.UseLibjpeg();
	codecs.UseLibpng();
	codecs.UseLibjxl();
	codecs.UseLibwebp();
});

var setting = new ProcessImageSettings
{
	MatteColor = Color.White
};

setting.Width = 1000;

setting.Height = 1000;


setting.TrySetEncoderFormat("image/webp");

using var ms= new MemoryStream();
var source = new MemoryStream(File.ReadAllBytes("C:\\t\\Test222.png"));
source.Position = 0;
MagicImageProcessor.ProcessImage(source, ms, setting);

using var fs= File.Create("C:\\t\\test.webp");
ms.Position = 0;
ms.CopyTo(fs);
fs.Flush();

Console.WriteLine("Finished");

if remove MatteColor = Color.White, it will work fine.

use latest package from azure:

  <ItemGroup>
    <PackageReference Include="PhotoSauce.NativeCodecs.Giflib" Version="5.2.2-ci242323" />
    <PackageReference Include="PhotoSauce.NativeCodecs.Libheif" Version="1.18.2-ci242323" />
    <PackageReference Include="PhotoSauce.NativeCodecs.Libjpeg" Version="3.0.3-ci242323" />
    <PackageReference Include="PhotoSauce.NativeCodecs.Libjxl" Version="0.10.3-ci242323" />
    <PackageReference Include="PhotoSauce.NativeCodecs.Libpng" Version="1.6.43-ci242323" />
    <PackageReference Include="PhotoSauce.NativeCodecs.Libwebp" Version="1.4.0-ci242323" />
  </ItemGroup>
@fengqiaoyexia
Copy link

also happened.

@saucecontrol
Copy link
Owner

Thanks for the report, but I'm not able to reproduce this after having tried lots of transparent PNG inputs. Can you provide an input image that fails, as well as your environment info?

@fengqiaoyexia
Copy link

fengqiaoyexia commented Sep 24, 2024

Hi @saucecontrol
Sure, here is my code and example image, you could test it
Code:
` CodecManager.Configure(codecs =>
{
codecs.UseGiflib();
codecs.UseLibheif();
codecs.UseLibjpeg();
codecs.UseLibpng();
codecs.UseLibjxl();
codecs.UseLibwebp();
});

	var setting = new ProcessImageSettings
	{

		//MatteColor = Color.White => if set color white, it will throw exception
	};

	setting.Width = 1000;

	setting.Height = 1000;

	setting.TrySetEncoderFormat("image/webp");

	using var ms = new MemoryStream();
	var source = new MemoryStream(File.ReadAllBytes("C:\\Users\\Rowan\\Pictures\\Logo2\\Test222.png"));
	source.Position = 0;
	MagicImageProcessor.ProcessImage(source, ms, setting);

	using var fs = File.Create("C:\\Users\\Rowan\\Pictures\\Logo2\\Result.webp");
	ms.Position = 0;
	ms.CopyTo(fs);
	fs.Flush();

	Console.WriteLine("Finished");`

Exception:
image

Example:
Test222

@saucecontrol
Copy link
Owner

Thanks @fengqiaoyexia, I see the issue now.

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

3 participants