예제 #1
0
        public MemoryStream ResizeImage(Stream source, int?maxWidth = null, int?maxHeight = null, int?quality = 0, object settings = null)
        {
            Guard.ArgumentNotNull(() => source);

            ResizeSettings resizeSettings = ImageResizerUtils.CreateResizeSettings(settings);

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

            var resultStream = new MemoryStream();

            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, ImageResizerUtils.CreateResizeSettings(settings));
            var localPath = this.GetImageLocalPath(imagePath);

            var result = new CachedImageResult
            {
                Path      = imagePath, //"Media/Thumbs/" + imagePath,
                LocalPath = localPath,
                FileName  = Path.GetFileName(imagePath),
                Extension = GetCleanFileExtension(imagePath),
                Exists    = File.Exists(localPath)
            };

            return(result);
        }