Hi nauna,
For resizing refer below article.
Use aspose imaging library to convert to webp format.
Add Aspose.Imaging dll in your project or install from nuget.
Install-Package Aspose.Imaging -Version 21.2.0
The use the below code to convert to webp format.
HTML
<asp:FileUpload ID="fuUpoload" runat="server" />
<asp:Button OnClick="OnUpload" Text="Upload" runat="server" />
Code
C#
protected void OnUpload(object sender, EventArgs e)
{
if (fuUpoload.HasFile)
{
string[] allowedImageTypes = new string[] { "image/jpeg", "image/png" };
if (allowedImageTypes.Contains(fuUpoload.PostedFile.ContentType.ToLower()))
{
string normalImagePath = System.IO.Path.Combine(Server.MapPath("~/Files"), fuUpoload.PostedFile.FileName);
string webPFileName = System.IO.Path.GetFileNameWithoutExtension(fuUpoload.PostedFile.FileName) + ".webp";
string webPImagePath = System.IO.Path.Combine(Server.MapPath("~/Files"), webPFileName);
fuUpoload.PostedFile.SaveAs(normalImagePath);
var document = Aspose.Imaging.Image.Load(normalImagePath);
Aspose.Imaging.ImageOptions.WebPOptions options = new Aspose.Imaging.ImageOptions.WebPOptions();
document.Save(webPImagePath, options);
}
}
}
VB.Net
Protected Sub OnUpload(ByVal sender As Object, ByVal e As EventArgs)
If fuUpoload.HasFile Then
Dim allowedImageTypes As String() = New String() {"image/jpeg", "image/png"}
If allowedImageTypes.Contains(fuUpoload.PostedFile.ContentType.ToLower()) Then
Dim normalImagePath As String = IO.Path.Combine(Server.MapPath("~/Files"), fuUpoload.PostedFile.FileName)
Dim webPFileName As String = IO.Path.GetFileNameWithoutExtension(fuUpoload.PostedFile.FileName) & ".webp"
Dim webPImagePath As String = IO.Path.Combine(Server.MapPath("~/Files"), webPFileName)
fuUpoload.PostedFile.SaveAs(normalImagePath)
Dim document = Aspose.Imaging.Image.Load(normalImagePath)
Dim options As Aspose.Imaging.ImageOptions.WebPOptions = New Aspose.Imaging.ImageOptions.WebPOptions()
document.Save(webPImagePath, options)
End If
End If
End Sub