public MemoryStream ResizeImage(Stream source, int?maxWidth = null, int?maxHeight = null, int?quality = 0, object settings = null)
        {
            Guard.NotNull(source, nameof(source));

            var resultStream   = new MemoryStream();
            var resizeSettings = ImageResizerUtil.CreateResizeSettings(settings);

            if (source.Length != 0)
            {
                if (quality.HasValue)
                {
                    resizeSettings.Quality = quality.Value;
                }
                if (maxHeight.HasValue)
                {
                    resizeSettings.MaxHeight = maxHeight.Value;
                }
                if (maxWidth.HasValue)
                {
                    resizeSettings.MaxWidth = maxWidth.Value;
                }

                ImageBuilder.Current.Build(source, resultStream, resizeSettings);
            }

            return(resultStream);
        }
示例#2
0
        public virtual CachedImageResult GetCachedImage(int?pictureId, string seoFileName, string extension, object settings = null)
        {
            var imagePath = this.GetCachedImagePath(pictureId, seoFileName, extension, ImageResizerUtil.CreateResizeSettings(settings));

            var result = new CachedImageResult
            {
                Path      = imagePath, //"Media/Thumbs/" + imagePath,
                FileName  = System.IO.Path.GetFileName(imagePath),
                Extension = GetCleanFileExtension(imagePath),
                Exists    = _fileSystem.FileExists(BuildPath(imagePath))
            };

            return(result);
        }