Zimg – A lightweight and high-performance image storage and processing system
github.com
github.com
Just a suggestion, but I think you could boost the performance of simple JPEG transformations (crop, rotate by multiples of 90 degrees, transpose/transverse) by using the transformation facilities of libjpeg or libturbojpeg (which has a far nicer API). For scaling there is also epeg which works directly with the DCT coefficients.
I created a Python library that uses these APIs and it beats all ImageMagick-based solutions by an order of magnitude: https://github.com/jbaiter/jpegtran-cffi
I started the server and it serves an index.html with an upload form which is nice. The upload response is an HTML page, too which states in the body where the uploaded file is accessible.
There I got curious… how would one use zimg uploads from app? I think the common use case would be: User upload images to a web app or an API app which then POSTs the image to zimg and puts the image location into a DB.
I tried POSTing images using curl having the vague hope the response would be something more machine readable than an HTML body. At first that seemed to be true because I used the wrong curl parameters and zimg couldn't find the image within the POST body and responded {"ret":false,"error":{"code":1,"message":"File type not support."}}. But once I got the curl parameters right (curl -XPOST --form userfile=@9393.jpg -i http://localhost:4869/upload.json) zimg again responded with HTML. Adding an accept header and/or a ".json" postfix to the URL didn't make a difference. Am I missing something?
Is there a possibility to restrict upload to local network only but allowing public download?
1. Using curl and multiform way can post file to zimg and will return a html result:
curl -F "blob=@testup.jpeg;type=image/jpeg" "http://127.0.0.1:4869/upload"
If you don't like upload files via multiform way, you can use raw post way. Use this command to upload image via raw post:
curl -H "Content-Type:jpeg" --data-binary @testup.jpeg "http://127.0.0.1:4869/upload"
You need tell zimg a header "Content-Type", the value is the type of image. This way will get a json result and the error message is in the table below:
{"ret":false,"error":{"code":0,"message":"Internal error."}} {"ret":false,"error":{"code":1,"message":"File type not support."}} {"ret":false,"error":{"code":2,"message":"Request method error."}} {"ret":false,"error":{"code":3,"message":"Access error."}} {"ret":false,"error":{"code":4,"message":"Request body parse error."}} {"ret":false,"error":{"code":5,"message":"Content-Length error."}} {"ret":false,"error":{"code":6,"message":"Content-Type error."}} {"ret":false,"error":{"code":7,"message":"File too large."}}
2. Upload and download access control. Just modify conf file like this:
upload_rule = 'allow 127.0.0.1;allow xx.xx.xxx.xxx/xx' download_rule = 'allow all'
The conf rule is like nginx.
3. Sorry for missing English documents.
It feels very fast—has anyone worked with this who can speak to its effectiveness in a production environment?
It'd be interesting to know who uses this.
Also, does Zimg provide a way to expire images if they haven't been used in 1 year - and if there isn't enough storage for anymore images, it deletes the last accessed image to create room (I know this can be done in nginx, maybe nginx is still the solution I need)?
Great project!