Dynamic Image Resizing Module v3

今天忽然看到收藏夹里有一个IIS Download的网站(http://www.iis.net/downloads),其实就是微软的IIS官网,于是就想着点进去看看有没有什么好玩的东西,果然没有辜负我的期望,找到了一个名叫Dynamic Image Resizing Module v3的组件,说白了,就是IIS上处理图片的组件,不同于其它IIS的图片处理组件,需要在服务器端里写出代码去处理图片,这款插件,只需要在IIS上配置上了,访问图片文件时,只需加上指定的参数,输出的图片就会按这些参数去处理.这是在组件说明里提到的.

怀着好奇的心情,我点进去看了下.Image Resizing,网站打不开,看样子是需要翻长城才能下载.这难不到我.也不是此文的关键点,就略过吧.下载来是带源码和示例的,我直接按配置说明,有三种方法安装使用

* For a Visual Studio project

1) Use Project->Add Reference to add ImageResizer.dll to the project. 
2) Change the Project's web.config file to match the settings in the included Web.Config file.

* If you have NuGet, simply go to Tools->Library Package Manager->Package Manager Console
and run "Install-Package ImageResizer.WebConfig"

* If you're installing this on an IIS website, 

1) Copy ImageResizer.dll and ImageResizer.pdb into the /bin directory of the site (create the folder if it doesn't exist.
2) Copy Web.config into the root of the website. If it already exists, you'll need to add the new settings into the old file.

<?xml version="1.0" encoding="UTF-8"?>
		<section name="resizer" type="ImageResizer.ResizerSection,ImageResizer"  requirePermission="false" />
        <defaultDocument enabled="true">
                <clear />
                <add value="index.asp" />
                <add value="index.php" />
                <add value="index.htm" />
                <add value="index.html" />
            <mimeMap fileExtension=".xz" mimeType="application/octet-stream" />
		<validation validateIntegratedModeConfiguration="false"/>
			<!-- This is for IIS7+ Integrated mode -->
			<add name="ImageResizingModule" type="ImageResizer.InterceptModule"/>

然后放一个800*600的图片f.jpg到要目剥下 ,在浏览器输入访问地址:http://test.test.com/f.jpg(如何在本机测试时使用域名?),显示的是原始图片


width, height - force the width and/or height to certain dimensions. Whitespace will be added if the aspect ratio is different.
maxwidth, maxheight - fit the image within the specified bounds. (Most often used)
crop=auto - Crop the image the the size specified by width and height. Centers and minimally crops to preserve aspect ratio.
crop=(x1,y1,x2,y2) - Crop the image to the specified rectangle on the source image. You can use negative coordinates to specifiy bottom-right relative locations.
rotate=degress - Rotate the image.
bgcolor=color name| hex code (6-char). Sets the background/whitespace color.
stretch=fill - Stretches the image to width and height if both are specified. This is the only way to lose aspect ratio.
scale=both|upscaleonly|downscaleonly - By default, images are never upscaled. Use &scale=both to grow an image.
flip=h|v|both - Flips the image after resizing.
sourceFlip=h|v|both - Flips the source image before resizing/rotation.
paddingWidth=px & paddingColor=color|hex. paddingColor defaults to bgcolor, which defaults to white.
borderWidth=px, borderColor=color|hex.
colors=2-255 - Control the palette size of PNG and GIF images. If omitted, PNGs will be 24-bit.
frame=x - Choose which frame of an animated GIF to display.
page=x - Choose which page of a multi-page TIFF document to display.