c# - 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:
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. 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.
推荐阅读
- css - 为什么`border-left`会影响CSS中椭圆的形状?
- r - 如何在 ShinyProxy 下的闪亮应用之间共享数据库连接池
- amazon-web-services - EC2上的lyft /制图,有可能吗?
- node.js - 面临与在节点中添加页眉和页脚相关的错误
- typescript - typescript - jest - tsconfig:在 Resolver.resolveModule (node_modules/jest-resolve/build/index.js:259:17) 找不到模块'../...'
- vercel - 如何将 Google Application Credentials/Secret 添加到 Vercel 部署?
- r - 基于 Reactable 复选框更改 Shiny App 中的数据框
- java - 解析包含更改键的嵌套 JSON 对象
- reactjs - 查找使用二次函数的范围滑块的初始百分比
- c - 打印引号内的内容的 C 程序。”。在文本文件中