SparrowDB is an image database that works like an append-only object store. Sparrow has tools that allow image processing and HTTP server to access images.
Sparrow consists of three files – the actual Sparrow store file containing the images data, plus an index file and a bloom filter file.
There is a corresponding data definition record followed by the image bytes for each image in the storage file. The index file provides the offset of the data definition in the storage file.
- Built-in HTTP API so you don't have to write any server side code to get up and running.
- Optimizations for image storing.
- Web Admin Panel.
- Create scripts with Lua for image processing.
This short guide will walk you through getting a basic server up and running, and demonstrate some simple reads and writes.
Creating a database:
curl -X PUT http://127.0.0.1:8081/api/database_name
Show databases:
curl -X GET http://127.0.0.1:8081/api/_all
Sending an image to database:
curl -i -X PUT -H "Content-Type: multipart/form-data" \
-F "uploadfile=@image.jpg" \
http://127.0.0.1:8081/api/database_name/image_key
Querying an image:
curl -X GET http://127.0.0.1:8081/api/database_name/image_key
Accessing image from browser:
http://localhost:8081/g/database_name/image_key
If is set in database configuration file, generate_token = true, SparrowDB will generate a token for each image uploaded. The token’s value is randomly assigned by and stored in database. The token effectively eliminates attacks aimed at guessing valid URLs for photos.
Accessing image from browser with token:
http://localhost:8081/g/database_name/image_key/token_value
SparrowDB uses bild to allow image processing using LUA script.
All SparrowDB scripts must be in 'scripts' folder.
Example of script with image effect:
-- If image name contains gray, use grayscale effect
if string.match(imageCtx:name(), "gray") then
imageCtx:grayscale()
end
-- If image name contains blue, use gaussian blur effect
if string.match(imageCtx:name(), "blur") then
imageCtx:gaussianBlur(3.0)
end
Example of script with pixel iteration:
-- create an editable image
p = sparrowRGBA.new(imageCtx)
-- get image bounds
b = p:bounds()
-- iterate over pixels
for i = 0, b['width'] do
for j = 0, b['height'] do
-- get current pixel color: red, green, blue, alpha
v = p:getPixel(i, j)
-- set current pixel color: red, green, blue, alpha
p:setPixel(i, j, v['red'], v['green'], v['blue'], v['alpha'])
end
end
-- set processed image as outputsss
imageCtx:setOutput(p)
This software is under MIT license.