Skip to content

Instantly share code, notes, and snippets.

@GroupDocsGists
Created February 2, 2023 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GroupDocsGists/f83c404300f93c8e19605f58063fb2e0 to your computer and use it in GitHub Desktop.
Save GroupDocsGists/f83c404300f93c8e19605f58063fb2e0 to your computer and use it in GitHub Desktop.
Convert WebP to JPG, PNG, GIF, TIFF, or PDF using C#
// Convert WebP image to JPG, PNG, BMP or any other format in C#
using (Converter converter = new Converter("path/image.webp"))
{
ImageConvertOptions options = new ImageConvertOptions
{ // Set the conversion format to JPG
Format = ImageFileType.Jpg
};
converter.Convert(@"path/converted-image.jpg", options);
}
// Convert WebP to PDF in C#
using (Converter converter = new Converter("path/image.webp"))
{
PdfConvertOptions options = new PdfConvertOptions();
converter.Convert(@"path/converted-webp-image.pdf", options);
}
// Apply effects while converting WebP image to other formats in C#
using (Converter converter = new Converter("path/image.webp"))
{
ImageConvertOptions options = new ImageConvertOptions
{
Format = ImageFileType.Jpg,
Grayscale = true, // Convert the image in Grayscale
Height = 141, // Resize the Image Height
Width = 167, // Resize the image Width
FlipMode = ImageFlipModes.FlipX, // Flip the image
Contrast = 50, // Change the contrast of image
RotateAngle = 90, // Rotate the image
Brightness = 50, // Change the brightness
Gamma = 0.5F, // Gamma Setting
Watermark = // Watermark Settings
{
Text = "GroupDocs",
Width = 100,
Height = 100,
Background = false,
Top = 70,
Left = 90,
RotationAngle = -45,
}
};
converter.Convert(@"path/converted-with-options.jpg", options);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment