Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kgiszewski/990b71bb54f474b77d7162fea8cbb065 to your computer and use it in GitHub Desktop.
Save kgiszewski/990b71bb54f474b77d7162fea8cbb065 to your computer and use it in GitHub Desktop.
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