imazen / imageflow-dotnet

The official .NET API for Imageflow, the Rust image processing and optimization engine for web servers
GNU Affero General Public License v3.0
143 stars 25 forks source link

After conversion from JPEG to WebP image increased in size #38

Closed NiJeTi closed 3 years ago

NiJeTi commented 3 years ago

Using library to reduce incoming images size.

Used code:

public async Task<MemoryStream> ConvertStreamAsync(Stream input, CancellationToken cancellationToken)
{
    Log.Debug("Converting image stream");

    using var imagesProcessor = new ImageJob();
    var output = new MemoryStream();

    await imagesProcessor
       .Decode(input, false)
       .EncodeToStream(output, false, new WebPLosslessEncoder())
       .Finish()
       .WithCancellationToken(cancellationToken)
       .InProcessAsync();

    output.Position = 0;

    Log.Debug("Done converting image stream");

    return output;
}

input stream can contain JPEG, PNG, WebP and GIF

After passing 1.1 MB JPEG to input I received 4,82 MB WebP image

lilith commented 3 years ago

Lossless formats take up much more space than lossy formats. You might try the lossy webp encoder and set an equivalent quality value to what the jpeg was created with.

On Sat, Jul 31, 2021, 3:22 PM Arkady Skvoretsky @.***> wrote:

Using library to reduce incoming images size.

Used code:

public async Task ConvertStreamAsync(Stream input, CancellationToken cancellationToken) { Log.Debug("Converting image stream");

using var imagesProcessor = new ImageJob();
var output = new MemoryStream();

await imagesProcessor
   .Decode(input, false)
   .EncodeToStream(output, false, new WebPLosslessEncoder())
   .Finish()
   .WithCancellationToken(cancellationToken)
   .InProcessAsync();

output.Position = 0;

Log.Debug("Done converting image stream");

return output;

}

input stream can contain JPEG, PNG, WebP and GIF

After passing 1.1 MB JPEG to input I received 4,82 MB WebP [image: image] https://user-images.githubusercontent.com/5685857/127752686-8bab1d0b-c107-43a3-b4ee-6dffbad07471.png

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/imazen/imageflow-dotnet/issues/38, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA2LH2RV44BUCWV4PAL5TLT2RSP3ANCNFSM5BKMP3XA .

NiJeTi commented 3 years ago

Thanks for the explanation!