/*
        private static void ApplyTransform(string imageName, string imagePath, string transformType)
        {
            int resX = transformType.X;
            int resY = transformType.Y;
            string saveAsPath = transformType.SaveAsPath;

            Image origImage = loadImage(imageName, imagePath);
            float resYPom = ((float)origImage.Height / (float)origImage.Width);
            resYPom = resYPom * resX;

            if (resY == 0)
            {
                resY = Convert.ToInt32(resYPom);
            }

            Bitmap thumbImage;
            Graphics g;

            switch (transformType)
            {
                case "resizeByLongerSide":
                    float origResX = origImage.Width;
                    float origResY = origImage.Height;

                    if (origResX > origResY)
                    {
                        resY = Convert.ToInt32((origResY / origResX) * resX);
                    }
                    else
                    {
                        if (origResY > origResX)
                        {
                            resX = Convert.ToInt32((origResX / origResY) * resY);
                        }
                    }
                    thumbImage = GetThumbImage(origImage, resX, resY);

                    break;

                case "ResizeAndCrop":
                    thumbImage = new Bitmap(resX, resY, origImage.PixelFormat);
                    g = Graphics.FromImage(thumbImage);
                    g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    g.SmoothingMode = SmoothingMode.HighQuality;
                    g.PixelOffsetMode = PixelOffsetMode.HighQuality;
                    g.CompositingQuality = CompositingQuality.HighQuality;

                    float origSizeX = origImage.Width;
                    float origSizeY = origImage.Height;

                    if (origSizeX == origSizeY) //ctverec, jen zmensime
                    {
                        thumbImage = GetThumbImage(origImage, resX, resY);
                    }

                    if (origSizeX >= origSizeY) //na sirku - orizneme na kazde strane pulku rozdilu (sirka - vyska)
                    {
                        int rozdil = Convert.ToInt32(origSizeX - origSizeY);
                        int rozdilPul = Convert.ToInt32(rozdil / 2);

                        g.DrawImage(origImage, new Rectangle(0, 0, resX, resY), rozdilPul, 0, (origSizeX - rozdil), origSizeY, GraphicsUnit.Pixel);
                    }
                    else // na vysku - orez se provadi v dolni casti
                    {
                        int rozdil = Convert.ToInt32(origSizeY - origSizeX);
                        g.DrawImage(origImage, new Rectangle(0, 0, resX, resY), 0, 0, origSizeX, (origSizeY - rozdil), GraphicsUnit.Pixel);
                    }

                    var simRAC1 = new SharpeningImage();
                    simRAC1.Filter(thumbImage);

                    break;
                default: //Zadne jmeno transformace nepasne, udela se jen resize
                    thumbImage = GetThumbImage(origImage, resX, resY);
                    break;
            }

            SaveImage(thumbImage, saveAsPath);

        }
        */
        private Bitmap GetThumbImage(Image origImage, int resX, int resY)
        {
            var thumbImage = new Bitmap(resX, resY, origImage.PixelFormat);
            var g = Graphics.FromImage(thumbImage);
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            g.SmoothingMode = SmoothingMode.HighQuality;
            g.PixelOffsetMode = PixelOffsetMode.HighQuality;
            g.CompositingQuality = CompositingQuality.HighQuality;

            var oRectangle = new Rectangle(0, 0, resX, resY);
            g.DrawImage(origImage, oRectangle);

            if (resX < origImage.Width)
            {
                var si = new SharpeningImage();
                si.Filter(thumbImage);
            }

            return thumbImage;
        }
        private Bitmap MakeSquareTransfrom(int resX, int resY, Image origImage)
        {
            var squareThumbImage = new Bitmap(resX, resY, origImage.PixelFormat);
            Graphics gr = Graphics.FromImage(squareThumbImage);
            gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
            gr.SmoothingMode = SmoothingMode.HighQuality;
            gr.PixelOffsetMode = PixelOffsetMode.HighQuality;
            gr.CompositingQuality = CompositingQuality.HighQuality;

            float origSizeX = origImage.Width;
            float origSizeY = origImage.Height;

            if (origSizeX == origSizeY) //ctverec, jen zmensime
            {
                squareThumbImage = GetThumbImage(origImage, resX, resY);
            }

            if (origSizeX >= origSizeY) //na sirku - orizneme na kazde strane pulku rozdilu (sirka - vyska)
            {
                int rozdil = Convert.ToInt32(origSizeX - origSizeY);
                int rozdilPul = Convert.ToInt32(rozdil/2);

                gr.DrawImage(origImage, new Rectangle(0, 0, resX, resY), rozdilPul, 0, (origSizeX - rozdil), origSizeY,
                             GraphicsUnit.Pixel);
            }
            else // na vysku - orez se provadi v dolni casti
            {
                int rozdil = Convert.ToInt32(origSizeY - origSizeX);
                gr.DrawImage(origImage, new Rectangle(0, 0, resX, resY), 0, 0, origSizeX, (origSizeY - rozdil),
                             GraphicsUnit.Pixel);
            }

            var simRAC1 = new SharpeningImage();
            simRAC1.Filter(squareThumbImage);

            return squareThumbImage;
        }
        private Bitmap DoResizeImage(Photo photo, PhotoType fromType, PhotoType targetType)
        {
            var fullPath = GetPhotoFullPath(photo, fromType);
            var origImage = LoadImage(fullPath);

            int resX = targetType.X;
            int resY;
            float ratio;

            //TODO: tady je chyba!!!!!! + tahle metoda se vola divne moc casto ???

            if (targetType.Y.HasValue) //mam zadanou vysku
            {
                resY = targetType.Y.Value;

                if (resX == resY) //ctvercova transformace
                {
                    return MakeSquareTransfrom(resX, resY, origImage);
                }
            }

            //obrazek na sirku nebo ctverec:
            if (origImage.Width >= origImage.Height)
            {
                ratio = (float)origImage.Height / (float)origImage.Width;
                resY = Convert.ToInt32(resX * ratio);
            }
            else //obrazek na vysku.
            {
                if(targetType.Y.HasValue) //mam zadanou vysku
                {
                    resY = targetType.Y.Value;
                    ratio = (float)origImage.Width / (float)origImage.Height;
                    resX = Convert.ToInt32(resY * ratio);
                }
                else //pokud nemam zadanou vysku, musim to resizovat podle zadane sirky
                {
                    ratio = (float)origImage.Height / (float)origImage.Width;
                    resY = Convert.ToInt32(resX * ratio);
                }
            }

            var thumbImage = new Bitmap(resX, resY, origImage.PixelFormat);
            Graphics g = Graphics.FromImage(thumbImage);
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            g.SmoothingMode = SmoothingMode.HighQuality;
            g.PixelOffsetMode = PixelOffsetMode.HighQuality;
            g.CompositingQuality = CompositingQuality.HighQuality;

            var oRectangle = new Rectangle(0, 0, resX, resY);
            g.DrawImage(origImage, oRectangle);

            if (resX < origImage.Width)
            {
                var si = new SharpeningImage();
                si.Filter(thumbImage);
            }

            origImage.Dispose();

            return thumbImage;
        }