WeddingPlatform.Web 1.0.0.0
지도, 갤러리, 방명록, 계좌 안내와 배경음악을 링크 하나에 담는 무료 모바일 청첩장 서비스입니다.
로딩중...
검색중...
일치하는것 없음
OgImageGenerator.cs
이 파일의 문서화 페이지로 가기
1using System.Drawing;
2using System.Drawing.Drawing2D;
3using System.Drawing.Imaging;
4using System.IO;
5
7
16public static class OgImageGenerator
17{
34 public static void EnsureGenerated(string wwwrootPath)
35 {
36 var imgDir = Path.Combine(wwwrootPath, "img");
37 var outPath = Path.Combine(imgDir, "og-platform.jpg");
38
39 if (File.Exists(outPath)) return;
40
41 Directory.CreateDirectory(imgDir);
42
43 const int W = 1200, H = 630;
44 using var bmp = new Bitmap(W, H, PixelFormat.Format32bppArgb);
45 using var g = Graphics.FromImage(bmp);
46 g.SmoothingMode = SmoothingMode.AntiAlias;
47 g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
48
49 // ── 배경 그라데이션 ───────────────────────────────────────
50 using (var bgBrush = new LinearGradientBrush(
51 new Point(0, 0), new Point(W, H),
52 Color.FromArgb(253, 246, 238),
53 Color.FromArgb(238, 220, 200)))
54 {
55 g.FillRectangle(bgBrush, 0, 0, W, H);
56 }
57
58 // ── 장식 원 ───────────────────────────────────────────────
59 DrawCircle(g, -80, -80, 320, 12);
60 DrawCircle(g, 920, 350, 400, 10);
61 DrawCircle(g, 970, -60, 160, 8);
62 DrawCircle(g, 50, 420, 200, 8);
63
64 // ── 카드 ─────────────────────────────────────────────────
65 var cardRect = new RectangleF(200, 100, 800, 430);
66 DrawRoundedRect(g, cardRect, 24,
67 Color.FromArgb(220, 255, 255, 255),
68 Color.FromArgb(80, 200, 168, 130), 2);
69
70 // ── 이모지 대신 하트 아이콘 (텍스트) ─────────────────────
71 using var iconFont = new Font("Segoe UI Emoji", 48, FontStyle.Regular, GraphicsUnit.Pixel);
72 DrawCenteredText(g, "💒", iconFont, Color.FromArgb(58, 46, 40), W / 2f, 200);
73
74 // ── 메인 타이틀 ───────────────────────────────────────────
75 using var titleFont = new Font("맑은 고딕", 46, FontStyle.Bold, GraphicsUnit.Pixel);
76 DrawCenteredText(g, "무료 모바일 청첩장", titleFont, Color.FromArgb(58, 46, 40), W / 2f, 285);
77
78 // ── 서브타이틀 ────────────────────────────────────────────
79 using var subFont = new Font("맑은 고딕", 22, FontStyle.Regular, GraphicsUnit.Pixel);
80 DrawCenteredText(g, "사진 · 음악 · 지도 · 방명록 · 계좌 안내", subFont,
81 Color.FromArgb(122, 106, 94), W / 2f, 348);
82
83 // ── 구분선 ────────────────────────────────────────────────
84 using var linePen = new Pen(Color.FromArgb(128, 200, 168, 130), 1.5f);
85 g.DrawLine(linePen, 420, 382, 780, 382);
86
87 // ── 배지 ─────────────────────────────────────────────────
88 var badgeRect = new RectangleF(470, 398, 260, 42);
89 using var badgeBrush = new SolidBrush(Color.FromArgb(200, 168, 130));
90 FillRoundedRect(g, badgeBrush, badgeRect, 21);
91 using var badgeFont = new Font("맑은 고딕", 17, FontStyle.Bold, GraphicsUnit.Pixel);
92 DrawCenteredText(g, "5분이면 완성 · 완전 무료", badgeFont, Color.White, W / 2f, 425);
93
94 // ── 도메인 ────────────────────────────────────────────────
95 using var domFont = new Font("Arial", 19, FontStyle.Regular, GraphicsUnit.Pixel);
96 DrawCenteredText(g, "wedding.codemaru.co.kr", domFont,
97 Color.FromArgb(100, 58, 46, 40), W / 2f, 492);
98
99 // ── JPEG 저장 ─────────────────────────────────────────────
100 var jpegParams = new EncoderParameters(1);
101 jpegParams.Param[0] = new EncoderParameter(Encoder.Quality, 92L);
102 var jpegCodec = ImageCodecInfo.GetImageEncoders()
103 .First(c => c.FormatID == ImageFormat.Jpeg.Guid);
104
105 bmp.Save(outPath, jpegCodec, jpegParams);
106 }
107
164 private static void DrawCenteredText(Graphics g, string text, Font font, Color color, float cx, float cy)
165 {
166 using var brush = new SolidBrush(color);
167 var size = g.MeasureString(text, font);
168 g.DrawString(text, font, brush, cx - size.Width / 2f, cy - size.Height / 2f);
169 }
170
219 private static void DrawCircle(Graphics g, float x, float y, float diameter, int alphaPercent)
220 {
221 int alpha = (int)(255 * alphaPercent / 100.0);
222 using var brush = new SolidBrush(Color.FromArgb(alpha, 200, 168, 130));
223 g.FillEllipse(brush, x, y, diameter, diameter);
224 }
225
282 private static void DrawRoundedRect(Graphics g, RectangleF rect, float radius,
283 Color fill, Color stroke, float strokeWidth)
284 {
285 using var path = RoundedRectPath(rect, radius);
286 using var fillBrush = new SolidBrush(fill);
287 g.FillPath(fillBrush, path);
288 using var pen = new Pen(stroke, strokeWidth);
289 g.DrawPath(pen, path);
290 }
291
332 private static void FillRoundedRect(Graphics g, Brush brush, RectangleF rect, float radius)
333 {
334 using var path = RoundedRectPath(rect, radius);
335 g.FillPath(brush, path);
336 }
337
370 private static GraphicsPath RoundedRectPath(RectangleF rect, float r)
371 {
372 var path = new GraphicsPath();
373 path.AddArc(rect.X, rect.Y, r * 2, r * 2, 180, 90);
374 path.AddArc(rect.Right - r * 2, rect.Y, r * 2, r * 2, 270, 90);
375 path.AddArc(rect.Right - r * 2, rect.Bottom - r * 2, r * 2, r * 2, 0, 90);
376 path.AddArc(rect.X, rect.Bottom - r * 2, r * 2, r * 2, 90, 90);
377 path.CloseFigure();
378 return path;
379 }
380}
static GraphicsPath RoundedRectPath(RectangleF rect, float r)
static void EnsureGenerated(string wwwrootPath)
static void DrawCircle(Graphics g, float x, float y, float diameter, int alphaPercent)
static void DrawCenteredText(Graphics g, string text, Font font, Color color, float cx, float cy)
static void DrawRoundedRect(Graphics g, RectangleF rect, float radius, Color fill, Color stroke, float strokeWidth)
static void FillRoundedRect(Graphics g, Brush brush, RectangleF rect, float radius)