简体   繁体   English

图片尺寸使用ImageResizer与Azure的功能应用越来越损坏

[英]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. 我使用VS2017开发了以下功能应用程序,并将其部署到Azure门户。

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: CorrectImage:

在此处输入图片说明

CorruptedImage: 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? 谁能帮我解决此问题?

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. 简而言之,我想说一下,请检查您在此过程中开发的所有功能应用程序,它们正在监视blob存储容器。 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. 如果您需要进一步的帮助,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM