Beispiel #1
0
        public Image ProcessImage(Image image, ImageSize size, ImageProportion proportion)
        {
            if (!Sizes.Contains(size))
            {
                throw new ArgumentException($"Parameter `{nameof(size)}` is not supported at the moment!");
            }

            if (!Proportions.Contains(proportion))
            {
                throw new ArgumentException($"Parameter `{nameof(size)}` is not supported at the moment!");
            }

            var formatter = ProportionServiceResolver(proportion);

            if (formatter is null)
            {
                throw new NotSupportedException($"Formatter of `{nameof(proportion)}` is not supported yet!");
            }

            if (size == ImageSize.Origin && proportion == ImageProportion.Origin)
            {
                return(image);
            }

            try
            {
                return(formatter.PrepareImage(ResizeImage, image, size));
            }
            catch (NotSupportedImageSizeException ex)
            {
                Logger.LogError(ex,
                                "An exception ocurred in {0} while processing image for different sizes!",
                                GetFullMemberName());
            }
            return(null);
        }