Created
May 13, 2019 13:05
-
-
Save kgiszewski/990b71bb54f474b77d7162fea8cbb065 to your computer and use it in GitHub Desktop.
This file contains 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
var overlaidImage = Image.FromFile(PATH_TO_WATERMARK); | |
using (var imageFactory = new ImageFactory(preserveExifData: true)) | |
{ | |
var factory = imageFactory.Load(IMAGE_STREAM_TO_ALTER); | |
using (var outStream = new MemoryStream()) | |
{ | |
factory.Overlay(new ImageLayer | |
{ | |
Image = overlaidImage, | |
Size = new Size(imageFactory.Image.Width, imageFactory.Image.Height) | |
}); | |
overlaidImage.Dispose(); | |
var mediaType = id.GetMediaType(); | |
if (mediaType == Constants.MediaType.Png) | |
{ | |
factory.Format(new PngFormat()) | |
.Save(outStream); | |
} | |
else if (mediaType == Constants.MediaType.Gif) | |
{ | |
factory.Format(new GifFormat()) | |
.Save(outStream); | |
} | |
else | |
{ | |
factory.Format(new JpegFormat { Quality = 100 }) | |
.Save(outStream); | |
} | |
//do something with your outStream | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment