使用带有Azure函数应用程序的ImageResizer损坏图像尺寸 [英] Image dimensions getting corrupted using ImageResizer with Azure function app

查看:81
本文介绍了使用带有Azure函数应用程序的ImageResizer损坏图像尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有一个输入和两个输出的天蓝色功能应用程序.在这种情况下,每当将图像上传到容器:原始图像时,都会触发功能应用程序,该程序将生成两个缩略图图像.

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.

我使用VS2017开发了以下功能应用程序,并部署到了Azure门户.

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

代码:

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:

损坏的图像:

我对多张图像进行了验证,但是看到了相同的问题.配置中等大小的图像总是会损坏.

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?

推荐答案

能否请您检查是否有任何其他功能应用程序处于运行状态.简而言之,我想说一下,请检查您在此过程中开发的所有功能应用程序,它们正在监视blob存储容器.我怀疑其他一些功能应用程序正在触发并导致此问题.请停止所有功能应用程序,然后仅运行所需的功能应用程序,以查看它是否可以解决您的问题.如果您需要进一步的帮助,请告诉我.

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.

这篇关于使用带有Azure函数应用程序的ImageResizer损坏图像尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆