예제 #1
0
        private static void ResizeImage(int width, int height, int quality, string options, IMagickImage magickImage)
        {
            magickImage.Quality = quality;
            magickImage.Strip();

            if (options.Contains("g")) //grayscale
            {
                magickImage.Grayscale(PixelIntensityMethod.Average);
            }
            if (width == magickImage.BaseWidth && height == magickImage.BaseHeight)
            {
                return;
            }
            else if (options.Contains("f") || options.Contains("t"))
            {
                magickImage.Resize(width, height);
            }
            else
            {
                var magickGeometry = new MagickGeometry(width, height)
                {
                    IgnoreAspectRatio = false, //保持长宽比
                    FillArea          = true
                };
                magickImage.Resize(magickGeometry);
                magickImage.Crop(magickGeometry, Gravity.Center);
            }
        }
예제 #2
0
        private static void ApplyEffect(IMagickImage image, ThumbnailEffectType effect)
        {
            switch (effect)
            {
            case ThumbnailEffectType.Grayscale:

                image.Grayscale();
                break;

            case ThumbnailEffectType.Sepia:

                image.SepiaTone();
                break;
            }
        }
예제 #3
0
        private static void ResizeImage(int requestWidth, int requestHeight, int quality, string options, IMagickImage image)
        {
            image.Quality = quality;

            image.Strip();

            if (options.Contains("g")) //grayscale
            {
                image.Grayscale(PixelIntensityMethod.Average);
            }

            if (image.BaseWidth == requestWidth && image.BaseHeight == requestHeight) //requested image is same size
            {
                return;
            }
            if (requestWidth == 0 && requestHeight == 0) //requested image is same size
            {
                return;
            }

            if (options.Contains("f") || options.Contains("t")) //scale with aspect of image
            {
                var size = new MagickGeometry(requestWidth, requestHeight);
                image.Resize(size);
            }
            else if (requestWidth == 0 || requestHeight == 0) //scale with aspect of image
            {
                var size = new MagickGeometry(requestWidth, requestHeight);
                image.Resize(size);
            }
            else // This will resize the image to a fixed size without maintaining the aspect ratio.
            {
                var size = new MagickGeometry(requestWidth, requestHeight)
                {
                    IgnoreAspectRatio = false, //keep aspect ratio!
                    FillArea          = true
                };
                image.Resize(size);
                image.Crop(size, Gravity.Center);
            }
        }
예제 #4
0
파일: AImage.cs 프로젝트: ogoun/darkset
 public void Grayscale()
 {
     _current.Grayscale();
 }