我正在尝试使用 ImageSharp.Web 通过查询字符串参数调整图像大小,例如:http://localhost:5001/content/photo/img.jpg?width=800&height=600
我创建了一个新的 MVC Asp.Net Core 3.1 项目,安装了软件包并按照文档进行操作
我尝试了所描述的最低配置和几种变体,但中间件似乎没有拦截图像请求。我总是得到原始图像并且不会触发错误。
我错过了什么吗?此功能的最低可能配置是多少?
谢了!
启动.cs:
public void ConfigureServices(IServiceCollection services)
{
services.AddDependencyInjectionSetup();
services.AddControllersWithViews();
//https://docs.sixlabors.com/articles/imagesharp.web/gettingstarted.html
services.AddImageSharp();
services.AddImageSharpCore(
options =>
{
options.MaxBrowserCacheDays = 7;
options.MaxCacheDays = 365;
options.CachedNameLength = 8;
options.OnParseCommands = _ => { };
options.OnBeforeSave = _ => { };
options.OnProcessed = _ => { };
options.OnPrepareResponse = _ => { };
})
.SetRequestParser<QueryCollectionRequestParser>()
.SetMemoryAllocator(provider => ArrayPoolMemoryAllocator.CreateWithMinimalPooling())
.Configure<PhysicalFileSystemCacheOptions>(options =>
{
options.CacheFolder = "imagesharp-cache";
})
.SetCache<PhysicalFileSystemCache>()
.SetCacheHash<CacheHash>()
.AddProvider<PhysicalFileSystemProvider>()
.AddProcessor<ResizeWebProcessor>()
.AddProcessor<FormatWebProcessor>();
}
public …Run Code Online (Sandbox Code Playgroud)