This repository has been archived by the owner on Oct 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainProgram.cs
90 lines (73 loc) · 3.5 KB
/
MainProgram.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using CommandLine;
using Pastel;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using FlagPFP.Processing;
using FlagPFP.Loading;
namespace FlagPFP.Main
{
public partial class MainProgram
{
//This program complies with the NO_COLOR standard as it uses the Pastel library.
static void Main(string[] args)
{
Parser parser = new Parser(config => config.HelpWriter = null);
ParserResult<Options> parseResult = parser.ParseArguments<Options>(args);
parseResult.WithNotParsed(err => DisplayHelp(parseResult));
parseResult.WithParsed(o =>
{
FlagLoader loader = new FlagLoader();
Dictionary<string, PrideFlag> flagDict = loader.LoadFlags("Flag JSONs");
if (!flagDict.TryGetValue(o.FlagType, out PrideFlag flagPath))
{
LogError($"{o.FlagType} isn't a valid flag type!\n");
Console.WriteLine("---Flag Types---".Pastel(Color.CornflowerBlue));
foreach (KeyValuePair<string, PrideFlag> pair in flagDict) WriteHeaders(pair.Value, false, true);
Environment.Exit(1);
}
WriteHeaders(flagPath);
Console.WriteLine("\nMaking image...".Pastel(Color.LightGreen));
ImageProcessing processing = new ImageProcessing();
Bitmap imageFile = null;
Bitmap flag = null;
try
{
imageFile = processing.LoadAndResizeBmp(o.ImageFile, o.Size, o.Size);
flag = processing.LoadAndResizeBmp("Flags/" + flagPath.FlagFile, o.Size, o.Size);
}
catch (Exception ex)
{
LogError(ex.StackTrace, true);
}
Bitmap croppedBmp = processing.CropPicture(ref imageFile, o.Size, false);
Bitmap flagBmp = processing.CropFlag(ref flag, o.PixelMargin);
Bitmap finalBmp = processing.StitchTogether(ref flagBmp, ref croppedBmp, o.InnerSize);
try { finalBmp.Save(o.Output, ImageFormat.Png); }
catch (Exception ex)
{
LogError(ex.StackTrace, true);
}
Console.WriteLine($"Success! Saved image \"{o.Output}\"".Pastel(Color.SpringGreen));
Console.WriteLine($"FlagPFP, by Aesthetical#9203, 2021.".Pastel(Color.PaleTurquoise));
Environment.Exit(0);
});
}
public class Options
{
[Option("image", Required = true, HelpText = "Image file to use.")]
public string ImageFile { get; set; }
[Option("flag", Required = true, HelpText = "The flag type.")]
public string FlagType { get; set; }
[Option("margin", Required = true, HelpText = "Pixel margin between border and inner window.")]
public int PixelMargin { get; set; }
[Option("insize", Required = true, HelpText = "Size of the inner image, for example, set it to more than the full image size to crop it.")]
public int InnerSize { get; set; }
[Option("fsize", Required = false, HelpText = "Full image size.", Default = (int)800)]
public int Size { get; set; }
[Option("output", Required = true, HelpText = "Output image file.")]
public string Output { get; set; }
}
}
}