Support for animated webp images #92
-
I try to scale / compress an animated webp and it becomes a static image. I tried to set output to GIF since GIF supports animations. No luck. Here is example code I used to download an animated webp image and compress it as a gif:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Looks like you're using the Windows built-in WebP codec, which doesn't support animation. There is a new plugin for MagicScaler that does support animated WebP decoding and encoding https://www.nuget.org/packages/PhotoSauce.NativeCodecs.Libwebp With that, your sample works fine. using System.Diagnostics;
using PhotoSauce.MagicScaler;
using PhotoSauce.NativeCodecs.Libwebp;
CodecManager.Configure(codecs => {
codecs.UseLibwebp();
});
var http = new HttpClient();
using var resp = await http.GetAsync("https://mathiasbynens.be/demo/animated-webp-supported.webp");
using var stream = await resp.Content.ReadAsStreamAsync();
using var ms = new MemoryStream();
stream.CopyTo(ms);
ms.Position = 0;
var settings = new ProcessImageSettings() {
Width = 320,
Height = 320,
ResizeMode = CropScaleMode.Contain, // keep aspect ratio
};
string filename = @$"c:\temp\compressed_{DateTime.Now.Ticks}.gif";
await Task.Factory.StartNew(() => MagicImageProcessor.ProcessImage(ms, filename, settings));
Process.Start(new ProcessStartInfo { FileName = filename, UseShellExecute = true }); Note that in your sample, since you are not disposing the output FileStream, it may not be be completely written and may not read correctly. You need to explicitly close or flush it before reading. Or you can pass the file name to |
Beta Was this translation helpful? Give feedback.
Looks like you're using the Windows built-in WebP codec, which doesn't support animation. There is a new plugin for MagicScaler that does support animated WebP decoding and encoding https://www.nuget.org/packages/PhotoSauce.NativeCodecs.Libwebp
With that, your sample works fine.