Пример #1
0
        public void AddImageToWatermark(string LocalPath)
        {
            //如果是图片,检查是否需要打水印
            switch (_mediaSettings.WatermarkType)
            {
            case 1:
                ImageResizerUtils.AddImageSignText(LocalPath, LocalPath,
                                                   _mediaSettings.WatermarkText, _mediaSettings.WatermarkPosition,
                                                   _mediaSettings.WatermarkImgQuality, _mediaSettings.WatermarkFont, _mediaSettings.WatermarkFontSize);
                break;

            case 2:
                ImageResizerUtils.AddImageSignPic(LocalPath, LocalPath,
                                                  GetDefaultPictureLocalPath(_mediaSettings.WatermarkName), _mediaSettings.WatermarkPosition,
                                                  _mediaSettings.WatermarkImgQuality, _mediaSettings.WatermarkTransparency);
                break;
            }
        }
Пример #2
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);
        }
Пример #3
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);
        }