Exemple #1
0
 public UploadImageResult Upload(Stream stream, string fileName)
 {
     using (var context = new UploadImageContext(stream, fileName))
     {
         return Upload(context);
     }
 }
Exemple #2
0
 public UploadImageResult Upload(HttpPostedFileBase file)
 {
     using (var context = new UploadImageContext(file))
     {
         return Upload(context);
     }
 }
Exemple #3
0
        public UploadImageResult Upload(string fileName)
        {
            _logger.Debug("Upload Image FileName\n\r==================");

            using (var context = new UploadImageContext(fileName))
            {
                return Upload(context);
            }
        }
        private void SaveSourceImage(UploadImageContext context)
        {
            _logger.Info("ImageSourceProcesser");

            try
            {
                string fileName = FileUtils.SaveImage(context.ImageStream, context.ImageExt, ImageStoreSettings.ImageDir);
                context.ImageUrl = ImageStoreSettings.ImageUrl + fileName;

                _logger.InfoFormat("ImageSourceProcesser Complete, fileName:{0}, compressUrl:{1}", fileName, context.CompressUrl);

            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message);
                _logger.Error(ex.StackTrace);
            }
        }
        public Size GetImageSize(UploadImageContext context)
        {
            var sourceImgSize = new Size();
            using (var originalImage = Image.FromStream(context.ImageStream))
            {
                sourceImgSize.Width = originalImage.Width;
                sourceImgSize.Height = originalImage.Height;
            }

            var width = sourceImgSize.Width;
            var height = sourceImgSize.Height;

            if (width > ImageConstants.MaxImageWidth)
            {
                var percent = ImageConstants.MaxImageWidth / (double)width;
                height = (int)(percent * height);
                width = ImageConstants.MaxImageWidth;
            }
            return new Size { Width = width, Height = height };
        }
Exemple #6
0
        private UploadImageResult Upload(UploadImageContext context)
        {
            _logger.Debug("Upload Image \n\r==================");

            int returnCode = _checkProcesser.Process(context);
            bool success = (returnCode == ImageErrorMessage.ImageUploadSucess);

            var result = new UploadImageResult
            {
                Success = success,
                ImageName = context.FileName,
                ImageUrl = context.ImageUrl,
                ThumbImageUrl = context.ThumbUrl,
                CompressImageUrl = context.CompressUrl,
                ReturnCode = returnCode
            };
            _logger.DebugFormat("the image {0} upload succeed!the image path was:{1}, thumb image path:{2}", result.ImageName, result.ImageUrl, result.ThumbImageUrl);
            _logger.Debug("\n\r===========================================");

            return result;
        }
        public override int Process(UploadImageContext context)
        {
            if (IsFileSizeExtendMaxSize(context.ContentContentLength))
            {
                _logger.InfoFormat("图片超过了大小,图片大小为{0}", context.ContentContentLength);
                return ImageErrorMessage.ImageTooLarge;
            }

            if (IsFileSizeIsNegative(context.ContentContentLength))
            {
                _logger.Info("图片大小为负数");
                return ImageErrorMessage.ImageNegative;
            }

            if (!IsImageTypeSupport(context.ImageExt))
            {
                _logger.InfoFormat("图片后缀为{0},后缀不支持", context.ImageExt);
                return ImageErrorMessage.ImageTypeNotSupport;
            }

            return NextProcesser.Process(context);
        }
        public override int Process(UploadImageContext context)
        {
            _logger.Debug("ImageThumbnailProcess");

            try
            {
                Size thumbnailSize = GetThumbnailSize(context.ImageStream);
                var stream = ImageCompress.CompressImage(context.ImageFormat, context.ImageStream, thumbnailSize, false);
                string fileName = FileUtils.SaveImage(stream, context.ImageExt, ImageStoreSettings.ThumbDir);
                context.ThumbUrl = ImageStoreSettings.ThumbUrl + fileName;

                _logger.InfoFormat("ImageSourceProcesser Complete, fileName:{0}, compressUrl:{1}", fileName, context.CompressUrl);

            }
            catch (Exception e)
            {
                _logger.Error(e.Message);
                return ImageErrorMessage.ImageUndefinedError;
            }

            return NextProcesser.Process(context);
        }
        public override int Process(UploadImageContext context)
        {
            _logger.Info("ImageCompressionProcesser");

            try
            {
                Size size = GetImageSize(context);

                var stream = ImageCompress.CompressImage(context.ImageFormat, context.ImageStream, size, true);

                string fileName = FileUtils.SaveImage(stream, context.ImageExt, ImageStoreSettings.CompressDir);
                context.CompressUrl = ImageStoreSettings.CompressUrl + fileName;

                _logger.InfoFormat("ImageCompressionProcesser Complete, fileName:{0}, compressUrl:{1}", fileName, context.CompressUrl);
            }
            catch (Exception e)
            {
                _logger.Error(e.Message);
                _logger.Error(e.StackTrace);
                return ImageErrorMessage.ImageUndefinedError;
            }

            return NextProcesser.Process(context);
        }
        public override int Process(UploadImageContext context)
        {
            _logger.Debug("ImageCompressionProcesser");

            return ImageErrorMessage.ImageUploadSucess;
        }
        public override int Process(UploadImageContext context)
        {
            SaveSourceImage(context);

            return NextProcesser.Process(context);
        }
 public abstract int Process(UploadImageContext context);