Customize image to your needs
First, we should download graphicsmagick
Install graphicsmagick
brew install graphicsmagick
sudo apt-get install graphicsmagick
npm install img-order
If you use experss or koa you just do this
var app = require('express'); // or app = ('koa')
var imgOrder = require('img-order');
var config = {
dest: 'absolute path to your image dir', // must
url: 'the client request url', // must
legalImg: 'jpg,jpeg,png,gif', // option
tempImgDir: 'cache temp images', // option(suggest to use)
maxAge: 2592000 // cache-control option
}
app.use(imgOrder(config));imageView /<mode>
/w/<Width>
/h/<Height>
/format/<Format>
| mode | Introduction |
|---|---|
/0/w/LongEdge/h/ShortEdge |
Limit the long sides of the thumbnail for a maximum of LongEdge, short edge up to ShortEdge, carries on the geometric scaling, not cut. If only specify w parameters is limited long (short) and adaptive, specify only h parameter indicates limited short side (long edge adaptive). |
/1/w/Width/h/Height |
Qualified thumbnail wide at least for Width, high minimum of Height, carries on the geometric scaling, center cut. After turning the thumbnail usually happens to be Width x Height size (one side when zooming by beyond rectangular box was cut off excess part). If you only specify w parameters or only specified h, on behalf of the limited to tetragonal figure is as broad as it is |
/2/w/Width/h/Height |
Limit the thumbnail Width up to Width, high up to Height, carries on the geometric scaling, not cut. If only specify w parameter represents finite width (adaptive), specify only h parameter finite long (wide adaptive). It similar to mode 0, the difference between just limit width and height, not qualified long side and short side. |
/3/w/Width/h/Height |
Qualified thumbnail wide at least for Width, high minimum of Height, carries on the geometric scaling, not cut. If only specify w parameters or only specified h, on behalf of the width is limited to the same value |
/4/w/LongEdge/h/ShortEdge |
CLimit the long sides of the thumbnail for at least the LongEdge, short edge at least for ShortEdge, carries on the geometric scaling, not cut. If you only specify w parameters or only specified h, said long should be the same value in a short while |
/5/w/LongEdge/h/ShortEdge |
Limit the long sides of the thumbnail for at least the LongEdge, short edge at least for ShortEdge, carries on the geometric scaling, center cut. If you only specify w parameters or only specified h, said long should be the same value in a short while. |
/format/format |
The output of the new format |
...
var imgOrder = require('img-order');
var config = {
dest: 'C:/Users/david/Pictures/lovewallpaper/',
url: 'customizeImg',
tempImgDir: 'C:/Users/david/Pictures/temp'
}
app.use(imgOrder(config));
/*
1.customize Image:
localhost:3100/customizeImg/zz.png?imageView/0/h/500
and so on...
2. format
localhost:3100/customizeImg/zz.png?/format/jpg
ad so on...
*/
...- thumbnail image
- image cut
- format image
- rotate image
- progressive display
- watermark
- EXIF(EXchangeable Image File Format)
根据需求定制自己需要的图片
首先我们需要下载graphicsmagick
安装graphicsmagick
brew install graphicsmagick
sudo apt-get install graphicsmagick
npm install img-order
If you use experss or koa you just do this
var app = require('express'); // or app = ('koa')
var imgOrder = require('img-order');
var config = {
dest: 'absolute path to your image dir', // 必须
url: 'the client request url', // 必须
legalImg: 'jpg,jpeg,png,gif', // 可选
tempImgDir: 'cache temp images', // 可选(推荐使用)
maxAge: 2592000 // 可选 cache-control
}
app.use(imgOrder(config));imageView /<mode>
/w/<Width>
/h/<Height>
/format/<Format>
| 模式 | 介绍 |
|---|---|
/0/w/LongEdge/h/ShortEdge |
限定缩略图的长边最多为,短边最多为ShortEdge,进行等比缩放,不裁剪。如果只指定 w 参数则表示限定长边(短边自适应),只指定 h 参数则表示限定短边(长边自适应) |
/1/w/Width/h/Height |
限定缩略图的宽最少为,高最少为Height,进行等比缩放,居中裁剪。转后的缩略图通常恰好是 WidthxHeight 的大小(有一个边缩放的时候会因为超出矩形框而被裁剪掉多余部分)。如果只指定 w 参数或只指定 h 参数,代表限定为长宽相等的正方图。 |
/2/w/Width/h/Height |
限定缩略图的宽最多为Width,高最多为Height,进行等比缩放,不裁剪。如果只指定 w 参数则表示限定宽(长自适应),只指定 h |
/3/w/Width/h/Height |
限定缩略图的宽最少为Width,高最少为Height,进行等比缩放,不裁剪。如果只指定w 参数或只指定h. 参数,代表长宽限定为同样的值 |
/4/w/LongEdge/h/ShortEdge |
限定缩略图的长边最少为LongEdge,短边最少为ShortEdge,进行等比缩放,不裁剪。如果只指定w 参数或只指定 h 参数,表示长边短边限定为同样的值 |
/5/w/LongEdge/h/ShortEdge |
限定缩略图的长边最少为LongEdge,短边最少为ShortEdge,进行等比缩放,居中裁剪。如果只指定w 参数或只指定h. 参数,表示长边短边限定为同样的值 |
/format/Format/ |
格式化输出图片 |
...
var imgOrder = require('img-order');
var config = {
dest: 'C:/Users/david/Pictures/lovewallpaper/',
url: 'customizeImg',
tempImgDir: 'C:/Users/david/Pictures/temp'
}
app.use(imgOrder(config));
...
/*
1.定制图片:
localhost:3100/customizeImg/zz.png?imageView/0/h/500
and so on...
2. 不同格式输出
localhost:3100/customizeImg/zz.png?/format/jpg
ad so on...
*/- 图片的缩略
- 图片裁剪
- 不同格式图片输出
- 旋转图片
- 图片的渐进显示
- 水印
- EXIF(EXchangeable Image File Format)
MIT