Beispiel #1
0
        public ActionResult ConvertedImage(string name)
        {
            var blobConnectionString = CloudConfigurationManager.GetSetting("BlobStorage.ConnectionString");

            var storageAccount = CloudStorageAccount.Parse(blobConnectionString);
            var blobClient     = storageAccount.CreateCloudBlobClient();
            var container      = blobClient.GetContainerReference("converted-images");

            container.CreateIfNotExists();

            var blob       = container.GetBlockBlobReference(name);
            var asciiImage = blob.DownloadText();

            var model = new AsciiImage {
                ImageText = asciiImage, Name = name
            };

            return(View(model));
        }
Beispiel #2
0
        public ActionResult AsciiArt(AsciiImage model)
        {
            if (!ModelState.IsValid)
            {
                // the user didn't upload any file =>
                // render the same view again in order to display the error message
                return(Content("oops"));
            }

            // http://stackoverflow.com/a/1171718/5415895
            Image img = Image.FromStream(model.File.InputStream, true, true);

            AsciiArt.AsciiArt ascii;

            // Valid height, invalid width.
            if (model.Height != null && model.Height > 0 && (model.Width == null || model.Width <= 0))
            {
                ascii = new AsciiArt.AsciiArt(img, model.Height.Value, model.Height.Value);
            }
            // Valid width, invalid height.
            else if ((model.Width != null || model.Width <= 0) && model.Height == null && model.Height > 0)
            {
                ascii = new AsciiArt.AsciiArt(img, model.Width.Value, model.Width.Value);
            }
            // Both inputs valid.
            else if (model.Height != null && model.Height > 0 && model.Width != null && model.Width > 0)
            {
                ascii = new AsciiArt.AsciiArt(img, model.Width.Value, model.Height.Value);
            }
            else
            {
                ascii = new AsciiArt.AsciiArt(img);
            }

            // http://stackoverflow.com/a/1569545/5415895
            //return File(Encoding.UTF8.GetBytes(ascii.Generate()), "text/plain", "art.txt");
            // For some reason this looks janky.
            return(Content(ascii.Generate(), "text/plain"));
        }