Пример #1
0
 public UploadedFilesResizer(IFileSystem files, ImageResizer resizer, EditSection config)
 {
     this.files = files;
     this.resizer = resizer;
     this.images = config.Images;
     sizeNames = config.Images.Sizes.AllElements.Select(s => s.Name).ToArray();
 }
Пример #2
0
        public void ProcessRequest(HttpContext context)
        {
            //UrlDecode is neccessary to compensate encoding in ImageAdapter
            string imageUrl = HttpUtility.UrlDecode(context.Request["img"]);
            string w        = context.Request["w"];
            string h        = context.Request["h"];
            string m        = context.Request["m"];

            double width = 0;

            double.TryParse(w, out width);

            double height = 0;

            double.TryParse(h, out height);

            ImageResizeMode mode;

            switch (m)
            {
            case "Fill":
                mode = ImageResizeMode.Fill;
                break;

            case "Stretch":
                mode = ImageResizeMode.Stretch;
                break;

            default:
                mode = ImageResizeMode.Fit;
                break;
            }

            IFileSystem fs = N2.Context.Current.Resolve <IFileSystem>();

            if (fs.FileExists(imageUrl))
            {
                string path = context.Server.MapPath(imageUrl);
                if (CacheUtility.IsModifiedSince(context.Request, path))
                {
                    CacheUtility.NotModified(context.Response);
                }

                context.Response.ContentType = "image/jpeg";

                string       extension = VirtualPathUtility.GetExtension(imageUrl);
                ImageResizer ir        = N2.Context.Current.Resolve <ImageResizer>();

                CacheUtility.SetValidUntilExpires(context.Response, TimeSpan.FromDays(7));
                using (var s = fs.OpenFile(imageUrl))
                {
                    var resized = ir.GetResizedBytes(s, extension, width, height, mode);
                    context.Response.BinaryWrite(resized);
                }
            }
            else
            {
                throw new HttpException(404, "Not found");
            }
        }
Пример #3
0
 public UploadedFilesResizer(IFileSystem files, ImageResizer resizer, EditSection config)
 {
     this.files = files;
     this.resizer = resizer;
     this.images = config.Images;
 }