/// <summary>convert webp image to png and resize image</summary> /// <param name="sourcePath">valid source image path</param> /// <param name="destPath">destination image path that saved image there</param> /// <param name="width">width that image resized to them</param> /// <param name="height">height that image resized to them</param> /// <param name="compress">compress image if that true</param> /// <returns>return true if do correctly else return false</returns> public static bool WebPToPng(string sourcePath, string destPath, int width, int height, bool compress = false) { try { if (String.IsNullOrEmpty(sourcePath) || String.IsNullOrEmpty(destPath) || width <= 0 || height <= 0) { return(false); } using (WebP webp = new WebP()) { var webp_byte = webp.LoadByte(sourcePath); Bitmap bmp; if (compress) { bmp = webp.GetThumbnailFast(webp_byte, width, height); } else { bmp = webp.GetThumbnailQuality(webp_byte, width, height); } bmp.Save(destPath, System.Drawing.Imaging.ImageFormat.Png); } return(true); } catch { throw; } }
/// <summary>convert webp image to jpeg</summary> /// <param name="sourcePath">valid source image path</param> /// <param name="destPath">destination image path that saved image there</param> /// <param name="compress">compress image if that true</param> /// <returns>return true if do correctly else return false</returns> public static bool WebPToJpeg(string sourcePath, string destPath, bool compress = false) { try { if (String.IsNullOrEmpty(sourcePath) || String.IsNullOrEmpty(destPath)) { return(false); } using (WebP webp = new WebP()) { var bmp = webp.Load(sourcePath); var webp_byte = webp.LoadByte(sourcePath); if (compress) { bmp = webp.GetThumbnailFast(webp_byte, bmp.Width, bmp.Height); } else { bmp = webp.GetThumbnailQuality(webp_byte, bmp.Width, bmp.Height); } bmp.Save(destPath, System.Drawing.Imaging.ImageFormat.Jpeg); } return(true); } catch { throw; } }