go get github.com/golang/groupcache
imagio
.There are two ways to build it, using the statically linked OpenCV libraries, which are attached to the release package or build it self.
If You don't have OpenCV and don't plan to use it further, just follow step 2.1.
Be sure, that GOROOT and GOPATH variables are set, and run script inside the imagio directory.
~/imagio# ./build-static.sh
That's all. You will get ready to use imagio
binary.
Install OpenCV and ensure that pkgconfig file is available, add it to PKG_CONFIG_PATH if needed.
# check it
pkg-config --libs opencv
# If You see an error about 'opencv.pc', run the following command
# with corresponding opencv path:
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/opencv-2.4.7/lib/pkgconfig
In couse of this bug Bug #1925, You should patch opencv.pc by running following command:
# copy-paste it
pcPrefix=`grep "prefix=" $PKG_CONFIG_PATH/opencv.pc | grep -v exec | sed 's/prefix=//g'`;pcLibs=`grep "Libs: " $PKG_CONFIG_PATH/opencv.pc`" -L$pcPrefix/lib";sed -i.old 's#libdir=#libdir='"$pcPrefix/lib"'#g' $PKG_CONFIG_PATH/opencv.pc;sed -i.old 's#Libs:.*#'"$pcLibs"'#g' $PKG_CONFIG_PATH/opencv.pc
# Install package by running:
go get github.com/3d0c/imagio
# Run it
$GOPATH/bin/imagio
For example:
curl -o test-800.jpg \
http://localhost:15900/\?scale=800x\&quality=80 \
\&source=farm5.staticflickr.com/4130/5088414872_0856bb93ed_o.jpg
You will get a downscaled to 800 px width jpeg, saved with 80% quality.
source
Possible values:
http://some.host.com/1.jpg
some.host.com/1.jpg
— scheme could be ommitted, http scheme is default1.jpg
— host could be ommitted, if it given in configfile://some/path/1.jpg
root option should be defined in config file, default is /tmp
scale
Prototype: ([0-9]+x) or (x[0-9]+) or ([0-9]+) or (0.[0-9]+)
E.g.:
800x
scale to width 800px, height will be calculatedx600
scale to height 600px, width will be calculated640
maximum dimension is 640px, e.g. original 1024x768 pixel image will be scaled to 640x480,
same option applied for 900x1600 image results 360x6400.5
50% of original dimensions, e.g. 1024x768 = 512x384crop
Prototype: crop=x,y,width,height
x,y
are the coordinates of top left corner of crop ROI and could be replaced by one of the following shortcuts:left
bleft
right
bright
center
quality
Jpeg quality. Integer value from 0 to 100. (more is better)
format
jpg
or png
. Could be omitted if no format conversion needed.
method
Scaling method. Default is Bicubic.
Possible values:
1
Nearest-neighbor interpolation2
Bilinear interpolation3
Bicubic interpolation4
Area based interpolation5
Lanczos resamplingblend_with Source for image, which will blended with the source image.
blend_mask Source for mask file.
blend_roi
(x,y) coordinates of the top left corner or one of the following shortcuts: left
, bleft
, right
, bright
, center
Default is (0,0)
blend_alpha Desired froreground image transparency. from 0.0 to 1.0 double. Use it only for blending two images without alpha channel. (See examples.)
If You need to change some default behavior, create an imagio.conf by running:
imagio -dumpcfg
It will create a default config file in the same directory:
{
"listen": "127.0.0.1:15900",
"source": {
"http": {
"root": "",
"default": true
},
"file": {
"root": "",
"default": false
}
},
"defaults": {
"format": "jpeg",
"method": 3,
"quality": 80,
"blend_alpha": 0.5
},
"groupcache": {
"self": "http://127.0.0.1:9100",
"peers": [],
"size": "512M"
}
}
It's pretty straightforward. Few comments:
root
option in file
sectionroot
in http
sectionpeers
is an array of strings, e.g. "peers" : ["host1:9100", "host2:9100"]
size
option supports M
for Megabytes and G
for GigabytesTo get a persistent watermark on every image add blend
section to the config file. E.g.:
"blend": {
"with": "file://watermark.png", // 'source->root' should be configured
// "http://localhost/watermark.png", // or common http url
"mask": "file://mask.png",
// "http://localhost/mask.png"
"roi": "0,0"
}
Note,
blend_alpha
settings is in defaults section.&source= |
&blend_with= |
&blend_mask= |
result |
---|---|---|---|
250x250 white |
&source= |
&blend_with= |
result |
---|---|---|
blend_alpha
option, by default it's 0.5
. &source= |
&blend_with= |
result |
---|---|---|