【发布时间】:2017-11-02 10:30:12
【问题描述】:
基于https://ppolyzos.com/2016/12/30/resize-images-using-azure-functions/,我有以下 C# 代码来使用 Azure Functions 调整图像大小。
#r "Microsoft.WindowsAzure.Storage"
using ImageResizer;
using ImageResizer.ExtensionMethods;
using Microsoft.WindowsAzure.Storage.Blob;
public static void Run(Stream inputBlob, string blobname, string blobextension, CloudBlockBlob outputBlob, TraceWriter log)
{
log.Info($"Resize function triggered\n Image name:{blobname} \n Size: {inputBlob.Length} Bytes");
log.Info("Processing 520x245");
/// Defining parameters for the Resizer plugin
var instructions = new Instructions
{
Width = 520,
Height = 245,
Mode = FitMode.Carve,
Scale = ScaleMode.Both
};
/// Resizing IMG
Stream stream = new MemoryStream();
ImageBuilder.Current.Build(new ImageJob(inputBlob, stream, instructions));
stream.Seek(0, SeekOrigin.Begin);
/// Changing the ContentType (MIME) for the resulting images
string contentType = $"image/{blobextension}";
outputBlob.Properties.ContentType = contentType;
outputBlob.UploadFromStream(stream);
}
结果将是一个名为520x245-{blobname}.{blobextension} 的图像。
我希望代码仅在 blob 容器中不存在生成的图像时运行。
如何获取容器上的现有文件?
【问题讨论】:
标签: azure azure-blob-storage azure-functions