-
Notifications
You must be signed in to change notification settings - Fork 0
/
HtmlWriter.cs
55 lines (50 loc) · 1.59 KB
/
HtmlWriter.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 System;
using System.IO;
using System.Text;
namespace Dithery_cli
{
public static class HtmlWriter
{
private static readonly string singleFileTemplate = @"<!doctype html>
<html lang=""en"">
<head>
<meta charset=""utf-8"">
<title>Dithery output</title>
<meta name=""description"" content=""Generated with Dithery"">
</head>
<body>
{0} <br> {1}
</body>
</html>";
private static readonly string allFilesTemplate = @"<!doctype html>
<html lang=""en"">
<head>
<meta charset=""utf-8"">
<title>Dithery output</title>
<meta name=""description"" content=""Generated with Dithery"">
</head>
<body>
{0}
</body>
</html>";
public static string GenerateSingleImageHtml((MemoryStream pngData, string text) original, (MemoryStream pngData, string text) dithered)
{
string originalImageHTML = GenerateImgSrcContent(original.pngData, original.text);
string ditheredImageHTML = GenerateImgSrcContent(dithered.pngData, dithered.text);
return string.Format(singleFileTemplate, originalImageHTML, ditheredImageHTML);
}
public static string GenerateMultiImageHtml((MemoryStream pngData, string text)[] images)
{
StringBuilder builder = new StringBuilder();
foreach ((MemoryStream pngData, string text) in images)
{
builder.AppendLine($"{GenerateImgSrcContent(pngData, text)} <br>");
}
return string.Format(allFilesTemplate, builder.ToString());
}
private static string GenerateImgSrcContent(MemoryStream pngMemoryStream, string title)
{
return $"<h3>{title}</h3><img alt=\"{title}\" src=\"data:image/png;base64,{Convert.ToBase64String(pngMemoryStream.ToArray())}\" />";
}
}
}