private void CreatePngThumbnail(Stream sourceStream, Stream destinationStream, Size size)
{
using (var image = Image.FromStream(sourceStream))
{
Image destination = image;
var diff = (destination.Width - destination.Height) / 2.0;
if (diff > 0)
{
var x1 = Convert.ToInt32(Math.Floor(diff));
var y1 = 0;
var x2 = destination.Height;
var y2 = destination.Height;
var rect = new Rectangle(x1, y1, x2, y2);
destination = ImageHelper.Crop(destination, rect);
}
else if (diff < 0)
{
diff = Math.Abs(diff);
var x1 = 0;
var y1 = Convert.ToInt32(Math.Floor(diff));
var x2 = destination.Width;
var y2 = destination.Width;
var rect = new Rectangle(x1, y1, x2, y2);
destination = ImageHelper.Crop(destination, rect);
}
destination = ImageHelper.Resize(destination, size);
destination.Save(destinationStream, ImageFormat.Png);
}
}