public static async Task <IActionResult> ThumbnailGenApi(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "generatethumbnail/{filename}")] HttpRequest req,
            [Blob("images/{filename}", FileAccess.Write)] Stream imageStream,
            [Blob("thumbnails/{filename}", FileAccess.Write)] Stream thumbnailImageStream,
            [VisionThumbnail(SmartCropping = true, Height = "150", Width = "150")] VisionThumbnailClient client,
            string fileName,
            TraceWriter log)
        {
            //Load Http Request Body into Thumbnail Request

            var request = new VisionThumbnailRequest(req.Body);

            //Generate Thumbnail
            var thumbnailBytes = await client.ThumbnailAsync(request);

            //Output Original Image to Blob Storage
            using (MemoryStream stream = new MemoryStream(request.ImageBytes))
            {
                await stream.CopyToAsync(imageStream);
            }

            //Output Thumbnail To Blob Storage
            using (MemoryStream stream = new MemoryStream(thumbnailBytes))
            {
                await stream.CopyToAsync(thumbnailImageStream);
            }


            return((ActionResult) new OkResult());
        }
            public async Task VisionThumbnailKeyvault(
                [VisionThumbnail(Width = "100", Height = "100")]
                VisionThumbnailClient client)
            {
                var request = new VisionThumbnailRequest();

                var result = await client.ThumbnailAsync(request);
            }
            public async Task VisionThumbnailWithTooBigImageBytes(
                [VisionThumbnail(AutoResize = false, Width = "100", Height = "100")]
                VisionThumbnailClient client)
            {
                var request = new VisionThumbnailRequest();

                request.ImageBytes = MockResults.SamplePhotoTooBig;

                var result = await client.ThumbnailAsync(request);
            }
            public async Task VisionThumbnailWithImageBytes(
                [VisionThumbnail(Width = "100", Height = "100")]
                VisionThumbnailClient client)
            {
                var request = new VisionThumbnailRequest();

                request.ImageBytes = MockResults.SamplePhoto;

                var result = await client.ThumbnailAsync(request);

                visionThumbnailResult = result;
            }
            public async Task VisionThumbnailWithUrl(
                [VisionThumbnail(Width = "100", Height = "100")]
                VisionThumbnailClient client)
            {
                var request = new VisionThumbnailRequest();

                request.ImageUrl = "http://www.blah";

                var result = await client.ThumbnailAsync(request);

                visionThumbnailResult = result;
            }
Ejemplo n.º 6
0
        public static async Task VisionThumbnailBlobFunction(
            [BlobTrigger("thumbnail/{name}")] Stream storageBlob,
            [VisionThumbnail(AutoResize = true,
                             Height = "100",
                             Width = "100",
                             SmartCropping = true)] VisionThumbnailClient visionclient,
            [Blob("thumbnailresults/{name}", FileAccess.Write)] Stream thumbnailBlob,
            string name,
            TraceWriter log
            )
        {
            var result = await visionclient.ThumbnailAsync(new VisionThumbnailRequest(storageBlob));

            using (MemoryStream stream = new MemoryStream(result))
            {
                await stream.CopyToAsync(thumbnailBlob);
            }

            log.Info($"Image thumbnail generated");
        }