-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
55 lines (47 loc) · 1.21 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
52
53
54
55
using HEIC2PNG;
using ImageMagick;
if (args.Length == 0 || args[0] == "help")
{
PrintHelp();
return;
}
var inputFile = args[0];
var outputFolder = args.Length == 2 ? args[1] : null;
string filePath = Path.Combine(AppContext.BaseDirectory, inputFile);
if (File.Exists(filePath))
{
ConvertFile(filePath);
} else if (Directory.Exists(filePath))
{
foreach (var file in Directory.GetFiles(filePath))
{
if(!file.EndsWith(".HEIC")) continue;
ConvertFile(file);
}
}
else
{
Console.WriteLine("Error: File or Directory not found. Please check the path or refer to the help page.");
}
return;
void PrintHelp()
{
Console.WriteLine(FileUtils.ReadLocalEmbeddedResource("help.txt"));
}
void ConvertFile(string inputFilePath)
{
var outputFilePath = $"{inputFilePath}.png";
try
{
using (MagickImage image = new MagickImage(inputFilePath))
{
image.Format = MagickFormat.Png;
image.Write(outputFilePath);
Console.WriteLine($"Successfully converted {Path.GetFileName($"{inputFilePath}")} to {Path.GetFileName(outputFilePath)}");
}
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}