private Image DrawText(string text, string baseImageName, string buttonText) { List <string> lines = new List <string>(text.Split(',').Select(x => x.Trim().ToUpper())); PictureManager pm = new PictureManager(); string version = "v1"; string resource = string.Empty; foreach (string line in lines) { resource += line.ToLower().Substring(0, 4); } string url = "https://careerthesaurus.blob.core.windows.net/share/" + version + "/" + resource + ".jpg"; if (pm.BlobExist("share", version, resource + ".jpg")) { return(null); } string filePath = System.Web.HttpContext.Current.Server.MapPath("\\content\\images\\FBShareBackgrounds\\" + baseImageName + ".jpg"); if (!System.IO.File.Exists(filePath)) { filePath = System.Web.HttpContext.Current.Server.MapPath("\\content\\images\\FBShareBackgrounds\\business.jpg"); } Image baseImage = (Bitmap)Image.FromFile(filePath); Image img = new Bitmap(1200, 630); Graphics drawing = Graphics.FromImage(img); drawing.DrawImage(baseImage, 0, 0); baseImage.Dispose(); drawing.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; drawing.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; int index = 0; int offset = 64; List <string> output = new List <string>(); if ((lines[0] + lines[1]).Length <= 25) { output.Add(lines[0] + ", " + lines[1]); output.Add(lines[2]); } else if ((lines[1] + lines[2]).Length <= 25) { output.Add(lines[0]); output.Add(lines[1] + ", " + lines[2]); } else { output.AddRange(lines); offset = 0; } Font textFont = new Font("Arial", 64, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel); int shadowOffset = 3; foreach (string line in output) { string str = line + (index < output.Count - 1 ? "," : ""); Image textImage = new Bitmap(1, 1); Graphics textGraphics = Graphics.FromImage(textImage); int textWidth = (int)textGraphics.MeasureString(str, textFont).Width; drawing.DrawString(str, textFont, new SolidBrush(Color.FromArgb(200, 0, 0, 0)), 600 - textWidth / 2 + shadowOffset, index * 72 + 150 + offset + shadowOffset); drawing.DrawString(str, textFont, new SolidBrush(Color.White), 600 - textWidth / 2, index * 72 + 150 + offset); textImage.Dispose(); textGraphics.Dispose(); index++; } Image buttonImage = new Bitmap(1, 1); Graphics buttonGraphics = Graphics.FromImage(buttonImage); Font buttonFont = new Font("Arial", 72, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel); int buttonTextWidth = (int)buttonGraphics.MeasureString(buttonText, buttonFont).Width; int buttonTextHeight = (int)buttonGraphics.MeasureString(buttonText, buttonFont).Height; int buttonTopPosition = 450; int buttonTextMargin = 20; //int buttonBorderWidth = 0; drawing.FillRectangle(new SolidBrush(Color.FromArgb(255, 204, 0)), 600 - buttonTextMargin * 2 - buttonTextWidth / 2, buttonTopPosition - buttonTextMargin / 4, buttonTextWidth + buttonTextMargin * 4, buttonTextHeight + buttonTextMargin * 2); //drawing.DrawRectangle(new Pen(Color.Black, buttonBorderWidth), new Rectangle(600 - buttonTextMargin - buttonTextWidth / 2, buttonTopPosition, buttonTextWidth + buttonTextMargin * 2, buttonTextHeight + buttonTextMargin * 2)); drawing.DrawString(buttonText, buttonFont, new SolidBrush(Color.Black), 600 - buttonTextWidth / 2, buttonTopPosition + buttonTextMargin); drawing.DrawString("I got:", new Font("Arial", 60, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel), new SolidBrush(Color.FromArgb(200, 0, 0, 0)), 60 + shadowOffset, 60 + shadowOffset); drawing.DrawString("I got:", new Font("Arial", 60, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel), new SolidBrush(Color.White), 60, 60); buttonImage.Dispose(); buttonGraphics.Dispose(); buttonFont.Dispose(); drawing.Flush(); //pm.UploadPictureToBlobStorage(img, resource, "share", version, 1200, 630, 50, 50, false, false); return(img); }