ShopPlatform.Web 1.0.0.0
농산물, 소프트웨어 라이선스와 개발 용역을 직접 판매하는 CodeMaru 직영 쇼핑몰입니다.
로딩중...
검색중...
일치하는것 없음
OgImageGenerator.cs
이 파일의 문서화 페이지로 가기
1using System.Drawing;
2using System.Drawing.Drawing2D;
3using System.Drawing.Imaging;
4using System.Drawing.Text;
5using System.Runtime.Versioning;
6
8
17public static class OgImageGenerator
18{
27 private const int W = 1200;
36 private const int H = 630;
37
54 public static void EnsureDefault(string wwwrootPath)
55 {
56 if (!OperatingSystem.IsWindowsVersionAtLeast(6, 1)) return; // Linux는 건너뜀
57 var dir = Path.Combine(wwwrootPath, "img");
58 var path = Path.Combine(dir, "shop-og-default.png");
59 Directory.CreateDirectory(dir);
60 if (File.Exists(path)) return;
61
62 using var bmp = new Bitmap(W, H, PixelFormat.Format32bppArgb);
63 using var g = Graphics.FromImage(bmp);
64 g.SmoothingMode = SmoothingMode.AntiAlias;
65 g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
66
67 // 그라데이션 배경 (진한 남색 → 보라)
68 using var bg = new LinearGradientBrush(
69 new Rectangle(0, 0, W, H),
70 Color.FromArgb(0x1e, 0x1b, 0x4b), // indigo-950
71 Color.FromArgb(0x4c, 0x1d, 0x95), // violet-900
72 LinearGradientMode.ForwardDiagonal);
73 g.FillRectangle(bg, 0, 0, W, H);
74
75 // 장식 원 (반투명)
76 using var circleBrush = new SolidBrush(Color.FromArgb(30, 255, 255, 255));
77 g.FillEllipse(circleBrush, -120, -120, 480, 480);
78 g.FillEllipse(circleBrush, W - 300, H - 300, 500, 500);
79
80 // 쇼핑백 아이콘 영역 (흰 둥근 사각형)
81 var iconRect = new Rectangle(W / 2 - 60, 140, 120, 120);
82 using var iconBg = new SolidBrush(Color.FromArgb(40, 255, 255, 255));
83 DrawRoundRect(g, iconBg, iconRect, 24);
84 using var iconFont = new Font("Segoe UI Emoji", 52, FontStyle.Regular, GraphicsUnit.Pixel);
85 using var iconBrush = new SolidBrush(Color.White);
86 var iconSf = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center };
87 g.DrawString("🛒", iconFont, iconBrush, new RectangleF(iconRect.X, iconRect.Y, iconRect.Width, iconRect.Height), iconSf);
88
89 // 메인 타이틀
90 using var titleFont = new Font("Malgun Gothic", 62, FontStyle.Bold, GraphicsUnit.Pixel);
91 using var titleBrush = new SolidBrush(Color.White);
92 var titleSf = new StringFormat { Alignment = StringAlignment.Center };
93 g.DrawString("ShopPlatform", titleFont, titleBrush, new RectangleF(0, 295, W, 80), titleSf);
94
95 // 부제목
96 using var subFont = new Font("Malgun Gothic", 30, FontStyle.Regular, GraphicsUnit.Pixel);
97 using var subBrush = new SolidBrush(Color.FromArgb(200, 255, 255, 255));
98 var subSf = new StringFormat { Alignment = StringAlignment.Center };
99 g.DrawString("나만의 온라인 쇼핑몰을 시작하세요", subFont, subBrush, new RectangleF(0, 378, W, 50), subSf);
100
101 // 하단 URL 배지
102 using var badgeBrush = new SolidBrush(Color.FromArgb(50, 255, 255, 255));
103 DrawRoundRect(g, badgeBrush, new Rectangle(W / 2 - 200, 470, 400, 46), 23);
104 using var urlFont = new Font("Malgun Gothic", 22, FontStyle.Regular, GraphicsUnit.Pixel);
105 using var urlBrush = new SolidBrush(Color.FromArgb(220, 255, 255, 255));
106 var urlSf = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center };
107 g.DrawString("shop.codemaru.co.kr", urlFont, urlBrush, new RectangleF(W / 2 - 200, 470, 400, 46), urlSf);
108
109 bmp.Save(path, ImageFormat.Png);
110 }
111
168 public static string EnsureShopOg(string wwwrootPath, string slug, string shopName, string description, string baseUrl)
169 {
170 if (!OperatingSystem.IsWindowsVersionAtLeast(6, 1))
171 return "/img/shop-og-default.png"; // Linux fallback
172 var dir = Path.Combine(wwwrootPath, "img", "og");
173 var fileName = $"og-{slug}.png";
174 var path = Path.Combine(dir, fileName);
175 Directory.CreateDirectory(dir);
176
177 // 항상 재생성 (설정 변경 반영)
178 using var bmp = new Bitmap(W, H, PixelFormat.Format32bppArgb);
179 using var g = Graphics.FromImage(bmp);
180 g.SmoothingMode = SmoothingMode.AntiAlias;
181 g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
182
183 // 배경
184 using var bg = new LinearGradientBrush(
185 new Rectangle(0, 0, W, H),
186 Color.FromArgb(0x1e, 0x1b, 0x4b),
187 Color.FromArgb(0x4c, 0x1d, 0x95),
188 LinearGradientMode.ForwardDiagonal);
189 g.FillRectangle(bg, 0, 0, W, H);
190
191 // 장식
192 using var circleBrush = new SolidBrush(Color.FromArgb(25, 255, 255, 255));
193 g.FillEllipse(circleBrush, -100, -100, 400, 400);
194 g.FillEllipse(circleBrush, W - 250, H - 250, 450, 450);
195
196 // 샵 이름
197 var nameText = shopName.Length > 18 ? shopName[..18] + "…" : shopName;
198 using var nameFont = new Font("Malgun Gothic", 72, FontStyle.Bold, GraphicsUnit.Pixel);
199 using var nameBrush = new SolidBrush(Color.White);
200 var centerSf = new StringFormat { Alignment = StringAlignment.Center };
201 g.DrawString(nameText, nameFont, nameBrush, new RectangleF(60, 200, W - 120, 90), centerSf);
202
203 // 설명
204 if (!string.IsNullOrEmpty(description))
205 {
206 var descText = description.Length > 40 ? description[..40] + "…" : description;
207 using var descFont = new Font("Malgun Gothic", 32, FontStyle.Regular, GraphicsUnit.Pixel);
208 using var descBrush = new SolidBrush(Color.FromArgb(210, 255, 255, 255));
209 g.DrawString(descText, descFont, descBrush, new RectangleF(60, 305, W - 120, 55), centerSf);
210 }
211
212 // 구분선
213 using var linePen = new Pen(Color.FromArgb(60, 255, 255, 255), 1);
214 g.DrawLine(linePen, 100, 390, W - 100, 390);
215
216 // 하단 플랫폼 표시
217 using var platformFont = new Font("Malgun Gothic", 24, FontStyle.Regular, GraphicsUnit.Pixel);
218 using var platformBrush = new SolidBrush(Color.FromArgb(160, 255, 255, 255));
219 g.DrawString($"🛒 {baseUrl.Replace("https://", "").Replace("http://", "")}/{slug}",
220 platformFont, platformBrush, new RectangleF(60, 415, W - 120, 40), centerSf);
221
222 bmp.Save(path, ImageFormat.Png);
223 return $"/img/og/{fileName}";
224 }
225
266 [SupportedOSPlatform("windows6.1")]
267 private static void DrawRoundRect(Graphics g, Brush brush, Rectangle rect, int radius)
268 {
269 using var path = new GraphicsPath();
270 path.AddArc(rect.X, rect.Y, radius * 2, radius * 2, 180, 90);
271 path.AddArc(rect.Right - radius * 2, rect.Y, radius * 2, radius * 2, 270, 90);
272 path.AddArc(rect.Right - radius * 2, rect.Bottom - radius * 2, radius * 2, radius * 2, 0, 90);
273 path.AddArc(rect.X, rect.Bottom - radius * 2, radius * 2, radius * 2, 90, 90);
274 path.CloseFigure();
275 g.FillPath(brush, path);
276 }
277}
static string EnsureShopOg(string wwwrootPath, string slug, string shopName, string description, string baseUrl)
static void EnsureDefault(string wwwrootPath)
static void DrawRoundRect(Graphics g, Brush brush, Rectangle rect, int radius)