Image Server 主要用来解决中小型网站和手机应用后台的图片存储、缩放以及智能裁剪等问题。
-
Install Redis
$ sudo apt-get install redis-server
-
Install Node.js
$ sudo apt-get install nodejs
-
Install Canvas dependencies
$ sudo apt-get install libjpeg-dev
$ sudo apt-get install libpango1.0-dev $ sudo apt-get install libcairo2-dev ```
-
Install GraphicsMagick
$ sudo apt-get install -y \ autoconf \ build-essential \ graphicsmagick \ libbz2-dev \ libcurl4-openssl-dev \ libevent-dev \ libffi-dev \ libglib2.0-dev \ libjpeg-dev \ liblzma-dev \ libncurses-dev \ libssl-dev \ libxml2-dev \ libxslt-dev \ libyaml-dev \ zlib1g-dev
-
Install SeaweedFS
-
Install go and set up $GOPATH Guide
-
Install mercurial
sudo apt-get install -y mercurial
-
Download, compile and install SeaweedFS
$ go get github.com/chrislusf/seaweedfs/go/weed
-
Start Master Server
$ $GOPATH/bin/weed master
-
Start Volume Servers
$ $GOPATH/bin/weed volume -dir="/tmp/data1" -max=5 -mserver="localhost:9333" -port=50070
-
-
Edit
/etc/hosts
file add below line127.0.0.1 image-server.redis.host 127.0.0.1 seaweedfs.master.host
-
Install Image Server
$ git clone https://github.com/ququzone/image-server.git $ cd image-server $ npm install $ node index.js
-
上传图片
在浏览器中打开
http://localhost:3000/image
上传图片也可以使用HttpClient
直接上传图片,返回 json 数据中包含上传成功后的唯一id -
查看原图
在浏览器中打开
http://localhost:3000/image/{id}
id是第一步 json 中返回的id,如果在应用中使用的时候可以采用客户端缓存图片,接口支持客户端缓存。
-
缩放
目前支持下面几种缩放方式:
http://localhost:3000/image/{id}/view?w=200
http://localhost:3000/image/{id}/view?h=200
http://localhost:3000/image/{id}/view?w=200&h=100
-
智能裁剪
http://localhost:3000/image/{id}/smart
http://localhost:3000/image/{id}/smart?w=200
http://localhost:3000/image/{id}/smart?h=200
http://localhost:3000/image/{id}/smart?w=200&h=100
-
首次安装
首次安装后,需要在浏览器中打开
http://localhost:3000
设置管理员帐号名和密码