.NET 缩略图服务器 ResizingServer

之前写过一篇文章

.NET 响应式自动缩略图服务器

之后对此Image Server又进行了基于ImageResizer的改写

  1. 基于.NET
  2. 图片服务器
  3. 支持缩略图格式
  4. 基于 ImageResizer

作为一个Web Server来部署 ResizingServer ,可以通过更改Web.Config

  <appSettings>
    <add key="UploadRouteUrl" value="api" /><!-- 设置上传时的Route规则 http://host/{UploadRouteUrl} -->
    <add key="ApiKey" value="48DFD0EE-61A2-4CB5-B1D6-33E917A83202" /><!-- 上传时所用的ApiKey -->
    <add key="AllowFolders" value="face,images" /><!-- 文件夹/类别 对不同业务线存储不同使用不同文件夹的情况 -->
  </appSettings>

 

物理路径 将类似 upload/face/1508/21/5a020a4161f543f197ddc0965aeeb66d.jpg

目录结构为

  • upload
    • category(AllowFolders 中所允许的都可以)
      • yyMM (年和月)
        • dd (天)
          • {guid}.jpg

上传后返回这样格式的URL /u/face/b96225af353d15504302a087f4f46bb0151d1c{0}x{1}{2}.jpg 称之为FormatUrl

通过 ResizingClient 的转换可以转换为这样

/u/face/b96225af353d15504302a087f4f46bb0151d1c100x100c.jpg

Client Demo

 

通过NuGet安装客户端

Install-Package ResizingClient

 

上传图片代码

var result=ResizingUtil.Upload(File.ReadAllBytes("d:\\a.jpg"), "a.jpg", "face").Result;
Console.WriteLine(result.FormatUrl);//like /u/face/b96225af353d15504302a087f4f46bb0151d1c{0}x{1}{2}.jpg
//Assert.IsTrue(result.IsSuccess);

 

{0}:宽 {1}:高 {2}:缩略模式

缩略模式:

  • c:crop
  • m:max
  • p:pad

转化FormatUrl

using ResizingClient;
// ...
var url1 = ResizingUtil.Format(url,100,100,ResizingMode.Pad);
var url1 = ResizingUtil.Format(url,100,100);

 

install from nuget downloads release

源代码地址

https://github.com/chsword/ResizingServer

 

posted @ 2015-08-22 17:52  重典  阅读(1185)  评论(2编辑  收藏  举报