ImageServer depends on flask
, celery
, redis
, PIL
, memcache
, requests
and Beansdb
. You should make sure those components avaliable before using ImageServer.
pip install cython
pip install -r requirements.txt
-
You need to setup Beansdb before use ImageServer.
beansdb -p 7901 -d -P/tmp/beansdb1.pid -L/tmp/beansdb1.log -H /home/gfreezy/beans/db/db1 -vv beansdb -p 7902 -d -P/tmp/beansdb2.pid -L/tmp/beansdb2.log -H /home/gfreezy/beans/db/db2 -vv
-
Customize settings.
Rename
sample_config.py
toconfig.py
. -
Run Server
Run the following commands in the directory of ImageServer.
$ python run.py
If you want ImageServer to auto synchronise your images to BaiduYun, start celery first. Run the command in a new shell.
$ celery worker -A simpleserver.init
-
POST /upload
Upload imageForm: image: Image string sizes(optional): 100x50,150x<60 (widthxheight or widthx<height) ident(optional): the ident to upload to callback: after syncing to bdyun, GET callback sync: whether sync to baiduyun Response: { "content": { "ident": "1c449b644ab111e3937900163e200a0a", "sizes": [ ["100", "50"], ["150", "<60"] ] }, "status": "ok" }
-
POST /sync/<ident>.jpg
Sync imageForm: sizes(optional): 100x50,150x<60 (widthxheight or widthx<height) callback: after syncing to bdyun, GET callback Response: { "content": { "ident": "1c449b644ab111e3937900163e200a0a", "sizes": [ ["100", "50"], ["150", "<60"] ] }, "status": "ok" }
-
POST /resize/<ident>.jpg
Resize imageForm: sizes(optional): 100x50,150x<60 callback: after syncing to bdyun, GET callback sync: true or false widthxheight or widthx<height Response: { "content": { "ident": "1c449b644ab111e3937900163e200a0a", "sizes": [ ["100", "50"], ["150", "<60"] ] }, "status": "ok" }
-
GET /image/<ident>.jpg
Visit image/image/1c449b644ab111e3937900163e200a0a.jpg?width=50&height=0 /image/1c449b644ab111e3937900163e200a0a.jpg?width=50&height=<50 /image/1c449b644ab111e3937900163e200a0a.jpg
Add the following config to your nginx config. Nginx will cache the images.
proxy_cache_path /var/www/cache levels=1:2 keys_zone=imageservice:10m max_size=1g inactive=24h;
proxy_temp_path /var/www/cache/tmp;
log_format imageservice
'$remote_addr '
'"$request" $status $bytes_sent '
'"$http_referer" "$http_user_agent" "$gzip_ratio" '
'$upstream_addr $upstream_cache_status';
server {
listen 8000;
location / {
proxy_pass http://localhost:8001;
}
location /image {
proxy_pass http://localhost:8001;
proxy_cache imageservice;
proxy_cache_valid 200 1d;
access_log /var/log/nginx/imageservice.log imageservice;
}
}