Last active
September 17, 2017 04:17
-
-
Save solster/0837b18386eeca13bb5da57b1fcf076c to your computer and use it in GitHub Desktop.
Azure Web Job for Compression Images
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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