public ActionResult Builder() { var url = Request.ServerVariables["HTTP_URL"]; var memeRequest = MemeRequest.FromUrl(url, Server); var meme = MemeUtilities.FindMeme(GlobalMemeConfiguration.Memes, memeRequest.Name); int memeLineCount; if (meme == null) { memeRequest.Name = "ihyk"; memeRequest.Lines = new List <string>() { "I'll have you know I tried other meme generators", "and only wasted hours and hours of my life" }; memeLineCount = GlobalMemeConfiguration.Memes[memeRequest.Name].Lines.Count; } else { memeLineCount = meme.Lines.Count; } var lines = Enumerable.Range(0, memeLineCount) .Select((item, index) => memeRequest.Lines.Count > index ? memeRequest.Lines[index] : string.Empty).ToList(); var viewModel = new BuilderViewModel { Memes = GlobalMemeConfiguration.Memes.GetMemes(), SelectedMeme = memeRequest.Name, Lines = lines }; return(View(viewModel)); }
public ActionResult Make() { var url = Request.ServerVariables["HTTP_URL"]; var memeRequest = MemeRequest.FromUrl(url, Server); var meme = MemeUtilities.FindMeme(GlobalMemeConfiguration.Memes, memeRequest.Name); if (meme == null) { // TODO: update this flow to return a proper HTTP 404 code, too meme = GlobalMemeConfiguration.NotFoundMeme; memeRequest.Lines = new List <string> { "404", "Y U NO USE VALID MEME NAME?" }; } // if we want to do this earlier in the process consider // if we still need to worry about png vs. jpg. The browser // probably doesn't care, but it might be weird if the extension // doesn't match the mimetype var hasExtension = UrlExtension.IsMatch(url); if (!hasExtension) { return(Redirect(url + Path.GetExtension(meme.ImageFileName))); } var renderParameters = new RenderParameters { FullImagePath = HttpContext.Server.MapPath(meme.ImagePath), DebugMode = memeRequest.IsDebugMode, FullWatermarkImageFilePath = HttpContext.Server.MapPath("~/Content/UpBoatWatermark.png"), WatermarkImageHeight = 25, WatermarkImageWidth = 25, WatermarkText = "upboat.me", WatermarkFont = "Arial", WatermarkFontStyle = FontStyle.Regular, WatermarkFontSize = 9, WatermarkStroke = Color.Black, WatermarkFill = Color.White, WatermarkStrokeWidth = 1, PrivateFonts = MemeConfig.PrivateFontCollection, Lines = meme.Lines.Select(l => new LineParameters { Bounds = l.Bounds, DoForceTextToAllCaps = l.DoForceTextToAllCaps, Fill = l.Fill, Font = l.Font, FontSize = l.FontSize, FontStyle = l.FontStyle, HeightPercent = l.HeightPercent, Stroke = l.Stroke, StrokeWidth = l.StrokeWidth, TextAlignment = l.TextAlignment, HugBottom = l.HugBottom }).ToList() }; for (var x = 0; x < renderParameters.Lines.Count; x++) { if (x < memeRequest.Lines.Count) { renderParameters.Lines[x].Text = memeRequest.Lines[x].SanitizeMemeText(renderParameters.Lines[x].DoForceTextToAllCaps); } } var renderer = new Renderer(); var bytes = renderer.Render(renderParameters); Analytics.TrackMeme(HttpContext, memeRequest.Name); return(new FileContentResult(bytes, meme.ImageType)); }