---
title: "Write WebP Lossy And Lossless"
canonical: https://www.graphicsmill.com/samples/Codecs/WebP/WriteWebPLossyAndLossless_cs
product: "Graphics Mill"
source: "Codecs/WebP/WriteWebPLossyAndLossless.cs"
---

# Write WebP Lossy And Lossless

Writes image in WebP lossy and lossless format.

## Instruction

Reads an image in JPEG format and saves it to WebP format in both lossy and lossless compression formats.

## Usings

```csharp
using System;
using Aurigma.GraphicsMill.Codecs;
```

## Code Snippet

```csharp
using (var reader = new JpegReader("Chicago.jpg"))
using (var writerLossy = new WebPWriter("WriteWebPLossy.webp"))
using (var writerLossless = new WebPWriter("WriteWebPLossless.webp"))
{
    writerLossy.Quality = 85f;
    Pipeline.Run(reader + writerLossy);

    writerLossy.FrameOptions.Lossless = true;
    Pipeline.Run(reader + writerLossless);
}

var lossy = new System.IO.FileInfo("WriteWebPLossy.webp");
var lossless = new System.IO.FileInfo("WriteWebPLossless.webp");

Console.WriteLine("Lossy WebP: {0} b", lossy.Length);
Console.WriteLine("Lossless WebP: {0} b", lossless.Length);
```

## Explanation

The following code:

- Loads the JPEG image using the `JpegReader`.
- Creates two WebP writers: one for lossy compression and one for lossless compression.
- Saves the image to WebP with lossy compression at a quality of 85.
- Saves the image to WebP with lossless compression.
- Prints the file sizes of the lossy and lossless WebP files.

## Tags

- [Compression](<https://www.graphicsmill.com/samples/tags/compression_md>): Tuning image compression settings
- [Format Conversion](<https://www.graphicsmill.com/samples/tags/format-conversion_md>): Converting images between formats
- [JPG](<https://www.graphicsmill.com/samples/tags/jpg_md>): Reading and writing JPEG images
- [Pipeline](<https://www.graphicsmill.com/samples/tags/pipeline_md>): Working with images via the Pipeline API
- [WEBP](<https://www.graphicsmill.com/samples/tags/webp_md>): Reading and writing WebP images

## Input

- [Chicago.jpg](<https://www.graphicsmill.com/samples/Codecs/compiled/Debug/Chicago_jpg>) (preview)

## Output

- [WriteWebPLossy.webp](<https://www.graphicsmill.com/samples/Codecs/compiled/Debug/WriteWebPLossy_webp>) (preview)
- [WriteWebPLossless.webp](<https://www.graphicsmill.com/samples/Codecs/compiled/Debug/WriteWebPLossless_webp>) (preview)

## Used APIs

- [Aurigma.GraphicsMill.Codecs.JpegReader](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_JpegReader.htm.md>)
- [Aurigma.GraphicsMill.Codecs.WebPFrameSettings.Lossless](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_WebPFrameSettings_Lossless.htm.md>)
- [Aurigma.GraphicsMill.Codecs.WebPWriter](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_WebPWriter.htm.md>)
- [Aurigma.GraphicsMill.Codecs.WebPWriter.FrameOptions](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_WebPWriter_FrameOptions.htm.md>)
- [Aurigma.GraphicsMill.Codecs.WebPWriter.Quality](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_WebPWriter_Quality.htm.md>)
