Skip to content

Instantly share code, notes, and snippets.

@solster
Last active September 17, 2017 04:17
Show Gist options
  • Select an option

  • Save solster/0837b18386eeca13bb5da57b1fcf076c to your computer and use it in GitHub Desktop.

Select an option

Save solster/0837b18386eeca13bb5da57b1fcf076c to your computer and use it in GitHub Desktop.
Azure Web Job for Compression Images
namespace Solster.Azure.WebJob.Compression
{
using Microsoft.Azure.WebJobs;
using System.IO;
using System.Drawing.Imaging;
using System.Linq;
using System.Drawing;
class Program
{
static void Main(string[] args)
{
var host = new JobHost();
host.RunAndBlock();
}
public static void ProcessQueueMessage([BlobTrigger("pictures/{name}")] Stream stream)
{
var codec = ImageCodecInfo.GetImageEncoders().Where(x => x.MimeType.Equals("image/jpeg")).First();
var encoderParams = new EncoderParameters(1) {
Param = new[] {
new EncoderParameter(Encoder.Quality, 50)
}
};
using (var image = Image.FromStream(stream))
{
stream.Position = 0;
image.Save(stream, codec, encoderParams);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment