Image dimensions getting corrupted using ImageResizer with Azure function app

柔情痞子 提交于 2019-12-25 00:55:33

问题


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:

CorruptedImage:

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?


回答1:


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.



来源:https://stackoverflow.com/questions/52225151/image-dimensions-getting-corrupted-using-imageresizer-with-azure-function-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!