首页 > 解决方案 > Image dimensions getting corrupted using ImageResizer with Azure function app

问题描述

I have a azure function app with one input and two outputs. In this case whenever an image is uploaded to a container: originals, the function app will be triggered which will generate two thumbnail images.

I developed the following function app using VS2017 and deployed to Azure portal.

Code:

using ImageResizer;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using System;
using System.Collections.Generic;
using System.IO;

namespace FunctionApp1
{
    public static class Function1
    {

        [FunctionName("Function1")]
        public static void Run(
                                [BlobTrigger("originals/{name}", Connection = "xxxxxxx")]Stream image,
                                [Blob("thumbs/s-{name}", FileAccess.ReadWrite, Connection = "xxxxxxx")]Stream imageSmall,
                                [Blob("thumbs/m-{name}", FileAccess.ReadWrite, Connection = "xxxxxxx")]Stream imageMedium,
                            TraceWriter log)
        {
            var imageBuilder = ImageResizer.ImageBuilder.Current;
            var size = imageDimensionsTable[ImageSize.Small];

            imageBuilder.Build(
                image, imageSmall,
                new ResizeSettings(size.Item1, size.Item2, FitMode.Max, null), false);

            image.Position = 0;
            size = imageDimensionsTable[ImageSize.Medium];

            imageBuilder.Build(
                image, imageMedium,
                new ResizeSettings(size.Item1, size.Item2, FitMode.Max, null), false);
        }

        public enum ImageSize
        {
            ExtraSmall, Small, Medium
        }

        private static Dictionary<ImageSize, Tuple<int, int>> imageDimensionsTable = new Dictionary<ImageSize, Tuple<int, int>>()
        {
            { ImageSize.ExtraSmall, Tuple.Create(320, 200) },
            { ImageSize.Small,      Tuple.Create(640, 400) },
            { ImageSize.Medium,     Tuple.Create(800, 600) }
        };

    }
}

On validating it, I found that it is generating two different images as per requirement, but I see one of the file is corrupted.

CorrectImage:

enter image description here

CorruptedImage:

enter image description here

I did the validation for multiple images but see the same issue. The image with medium size configuration always gets corrupted.

Any rectifications to the above code is much helpful.

Can anyone help me to fix this issue?

标签: c#azureazure-functionsimageresizer

解决方案


Can you please check is there any other function app already in running status. In short I would like to say that check all the function apps that you have developed in this process, which is monitoring the blob storage container. I suspect that some other function app is getting triggered and causing the issue here. Please stop all the function apps and only run the required function app to see if it resolves your issue. Please let me know in case you need any further help on this.


推荐阅读