-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
51 lines (46 loc) · 1.79 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
namespace UMapx.Imaging.Webp.Example
{
internal static class Program
{
static void Main()
{
Console.WriteLine("UMapx.Imaging.Webp example");
var files = Directory.GetFiles(@"..\..\..\images", "*.*", SearchOption.AllDirectories);
var path = @"..\..\..\results";
Directory.CreateDirectory(path);
Console.WriteLine($"Processing {files.Length} images");
foreach (var file in files)
{
Console.WriteLine($"Reading {file}");
if (file.EndsWith(".jpeg") ||
file.EndsWith(".jpg"))
{
using var bitmap = new Bitmap(file);
var webP = bitmap.ToWebp();
var filename = Path.Combine(path, $"{Path.GetFileNameWithoutExtension(file)}.webp");
File.WriteAllBytes(filename, webP);
Console.WriteLine($"Image save as {filename}");
}
else if (file.EndsWith(".webp"))
{
var webp = File.ReadAllBytes(file);
using var bitmap = BitmapWebp.FromWebp(webp);
using var jpeg = bitmap.ToJpeg();
var filename = Path.Combine(path, $"{Path.GetFileNameWithoutExtension(file)}.jpg");
jpeg.Save(filename, ImageFormat.Jpeg);
Console.WriteLine($"Image save as {filename}");
}
else
{
Console.WriteLine($"Could not recognize image format {file}");
}
}
Console.WriteLine("Done.");
Console.ReadKey();
}
}
}