PhotoSauce icon indicating copy to clipboard operation
PhotoSauce copied to clipboard

Png to Webp with MatteColor will throw Unsupported pixel format exception

Open JasonLiuLiuLiuLiu opened this issue 1 year ago • 4 comments

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>

JasonLiuLiuLiuLiu avatar Sep 05 '24 09:09 JasonLiuLiuLiuLiu

also happened.

fengqiaoyexia avatar Sep 05 '24 09:09 fengqiaoyexia

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?

saucecontrol avatar Sep 14 '24 18:09 saucecontrol

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

fengqiaoyexia avatar Sep 24 '24 08:09 fengqiaoyexia

Thanks @fengqiaoyexia, I see the issue now.

saucecontrol avatar Sep 30 '24 07:09 saucecontrol

This is fixed in v0.15.0. Thanks again for the report!

saucecontrol avatar Dec 05 '24 07:12 saucecontrol