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

Webp files are not animated after cropping #2952

Closed
1 task done
DrBenvey opened this issue Jul 22, 2024 · 1 comment
Closed
1 task done

Webp files are not animated after cropping #2952

DrBenvey opened this issue Jul 22, 2024 · 1 comment
Labels

Comments

@DrBenvey
Copy link

Description

I try to crop .webp
But they down have animation after i finish
Could u please provide an example of croping webp images

Code

private static Stream GetOutputStream(string name)
{
    return File.Open($"C:\\Users\\user\\Pictures\\animate\\output_{name}.webp", FileMode.OpenOrCreate);
}

private static Stream GetStream()
{
    return File.OpenRead("C:\\Users\\user\\Pictures\\animate\\2.webp");
}

public ImageCrop() 
{

    const int Width = 1200;
    const int Height = 1200;

    using var stream = GetStream();
    using var skData = SKData.Create(stream);
    using var codec = SKCodec.Create(skData);

    var supportedScale = codec
         .GetScaledDimensions((float)Width / codec.Info.Width);

    var nearest = new SKImageInfo(supportedScale.Width, supportedScale.Height);
    using var destinationImage = SKBitmap.Decode(codec, nearest);
    using var resizedImage = destinationImage.Resize(new SKImageInfo(Width, Height), SKFilterQuality.High);

    var format = SKEncodedImageFormat.Webp;
    using var outputImage = SKImage.FromBitmap(resizedImage);
    using var data = outputImage.Encode(format, 90);
    using var outputStream = GetOutputStream("skiasharp");
    data.SaveTo(outputStream);

    outputStream.Close();
    stream.Close();
}

Expected Behavior

new .webp image have animation

Actual Behavior

new .webp image dont have animation

Version of SkiaSharp

2.88.3 (Current)

Last Known Good Version of SkiaSharp

2.88.2 (Previous)

IDE / Editor

Visual Studio (Windows)

Platform / Operating System

Windows

Platform / Operating System Version

No response

Devices

No response

Relevant Screenshots

No response

Relevant Log Output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@mattleibow mattleibow changed the title Crop webp[BUG] <title> Webp files are not animated after cropping Sep 18, 2024
@mattleibow
Copy link
Contributor

This happens because you are loading the animated image, but the resize method just resizes and return the first frame.

SkiaSharp is designed for drawing things to a screen as fast as possible. One of its limitations is the ability to generate complex files - like animated images or encoding codecs.

ImageSharp (https://github.com/SixLabors/ImageSharp) may be able to do this. That library focuses on image loading, manipulation and encoding - among other things.

I will close this issue for now as this particular feature is out of scope of SkiaSharp.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants