Exemplo n.º 1
0
        public static MemoryStream MakeBlurpleFromStream(BlurpleOptions opt)
        {
            Image <Rgba32> img = Image.Load(opt.GetSourceImage());

            img.Mutate(x =>
            {
                x.GaussianBlur(opt.Preblur <= 0 ? 0.00001f : opt.Preblur)
                .ApplyProcessor(new BlurpleProcessor(opt));
            });

            MemoryStream imgPngData = new MemoryStream();

            img.SaveAsPng(imgPngData);

            imgPngData.Seek(0, SeekOrigin.Begin);

            return(imgPngData);
        }
Exemplo n.º 2
0
        public static IActionResult Run([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] BlurpleOptions opt, TraceWriter log)
        {
            log.Info($"Image blurple request recieved.");

            try
            {
                opt.Validate();

                Stopwatch watch = new Stopwatch();
                watch.Start();

                var mem    = MakeBlurpleFromStream(opt);
                var result = new FileStreamResult(mem, "image/png");

                watch.Stop();

                log.Info($"Converted image, took {watch.ElapsedMilliseconds}ms");

                return(result);
            }
            catch (NotSupportedException ex)
            {
                log.Error(ex.Message, ex);
                return(new BadRequestObjectResult("Image format not supported."));
            }
            catch (ArgumentOutOfRangeException ex)
            {
                log.Error(ex.Message, ex);
                return(new BadRequestObjectResult(ex.Message));
            }
            catch (Exception ex)
            {
                log.Error(ex.Message, ex);
            }

            return(new BadRequestObjectResult("There was an error of some kind."));
        }
Exemplo n.º 3
0
 public BlurpleProcessor(BlurpleOptions opt)
 {
     _opt = opt;
 }