这两款库都是非常有优秀的,基于这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)
{
}
}
}