.net图片拦截处理库ImageResizer,imageflow

这两款库都是非常有优秀的,基于这2款库,可以自己搭建一个图片资源服务器。

ImageResizer:https://github.com/imazen/resizer

imageflow:https://github.com/imazen/imageflow

具体看开源项目说明,使用起来是非常便捷的。

 

使用ImageResizer的时候,需要进行配置

<configuration>
  <configSections>
    <section name="resizer" type="ImageResizer.ResizerSection" requirePermission="false" />
  </configSections>
  
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
    <httpModules>
      <add name="ImageResizingModule" type="ImageResizer.InterceptModule" />
    </httpModules>
  </system.web>
  
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules>
      <add name="ImageResizingModule" type="ImageResizer.InterceptModule" />
    </modules>
  </system.webServer>
</configuration>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
//
using ImageResizer.Plugins;

namespace WebApplication1
{

    namespace MyNamespace
    {
        public class SimplePlugin : IPlugin
        {
            public IPlugin Install(ImageResizer.Configuration.Config c)
            {
                c.Plugins.add_plugin(this);
                return this;
            }

            public bool Uninstall(ImageResizer.Configuration.Config c)
            {
                c.Plugins.remove_plugin(this);
                return true; //True for successfull uninstallation, false if we couldn't do a clean job of it.
            }
        }
    }

    public class Global : System.Web.HttpApplication
    {
        protected void Application_Start(object sender, EventArgs e)
        {
            //注册plugin
            //new MyNamespace.SimplePlugin().Install(ImageResizer.Configuration.Config.Current);

            //针对folder目录下的图片,默认宽度都是100
            ImageResizer.Configuration.Config.Current.Pipeline.Rewrite +=
            delegate (IHttpModule s, HttpContext c, ImageResizer.Configuration.IUrlEventArgs ev)
            {
                if (ev.VirtualPath.StartsWith(VirtualPathUtility.ToAbsolute("~/folder/"), StringComparison.OrdinalIgnoreCase))
                    ev.QueryString["width"] = "100";
            };
        }               
        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }
        protected void Application_Error(object sender, EventArgs e)
        {

        }
        protected void Application_End(object sender, EventArgs e)
        {

        }
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值