0
votes

I completed the following tutorial to write a function (see code snippet) through which each time I add something to my Azure Blob storage, a resized copy will be saved in an additional container.

https://ppolyzos.com/2016/12/30/resize-images-using-azure-functions/

The problem is that Azure blob storage stores the resized images as octet-stream (Azure's default setting) rather than as in previous jpg format

The following tutorial says I can simply add Format = Jpeg; to achieve that format as demonstrated in the code snippet below.

http://jameschambers.com/2016/11/Resizing-Images-Using-Azure-Functions/

Does anybody know how I can keep the original format jpeg when making a resized copy of an image using azure functions?

using ImageResizer;
using ImageResizer.ExtensionMethods;

public static void Run(Stream myBlob, string blobname, string blobextension, Stream outputBlob, TraceWriter log)
{
    log.Info($"C# Blob trigger function Processed blob\n Name:{blobname} \n Size: {myBlob.Length} Bytes");

    var instructions = new Instructions    
    {        
        Width = 200,        
        Mode = FitMode.Carve,        
        Scale = ScaleMode.Both,
        Format = Jpeg    
    };
    instructions.OutputFormat = OutputFormat.Jpeg;
    ImageBuilder.Current.Build(new ImageJob(myBlob, outputBlob, instructions));
}

Many thanks!

1
So, your original file is jpeg, and your output file is jpeg. Can you explain what issue do you have with file format? Are you saying that OutputFormat.Jpeg setting is not working as expected?RAS

1 Answers

0
votes

As far as I know, the azure function generate the file’s format is according to the output’s path.

Like below:

The outputs: enter image description here

The tiggers: enter image description here

If you set the path as “gallery-resized/{blobname}-w200.{blobextension}”, this will generate the file according the inputblob file’s blobname and blobextension.

I suggest you could check your tiggers path's parameter is as same as the outputs path's parameter, firstly.

You couldn’t change its format in the function code, since the function will generate the file automatic.

If you want to change all file's format to jpg, I suggest you change the ouput’s path as below:

gallery-resized/{blobname}-w200.jpg

Then it will always generate the jpg format output.

Result:

enter image description here