﻿using System;
using System.Drawing;
using System.IO;
using ImageResizer;

namespace Postcard.Processing.Transformation
{
    /// <summary>
    /// Обрезка
    /// </summary>
    public class Crop : ITask
    {
        public int Height { get; set; }
        public int Width { get; set; }

        public Image Apply(Image image)
        {
            var setting = new ResizeSettings(String.Format("w={0}&h={1}&mode=crop&scale=both", Width, Height));
            var srcImage = Path.GetTempFileName();
            image.Save(srcImage);
            var outImage = Path.GetTempFileName();
            ImageBuilder.Current.Build(srcImage, outImage, setting);
            return Image.FromFile(outImage);
        }
    }
}
