Commit 49490726 authored by Juergen Enge's avatar Juergen Enge
Browse files

crop added

parent 7e08c7c4
Pipeline #13788 passed with stages
in 3 minutes and 22 seconds
......@@ -62,6 +62,7 @@ func (iai *ImageActionIIIF) Do(w http.ResponseWriter, req *http.Request, me *Med
return false, emperror.Wrapf(err, "invalid height %v in resize", resizeParams[1])
}
size := fmt.Sprintf("%v,%v", width, height)
var format string
if formatParams, ok := ps["format"]; ok {
format = strings.ToLower(formatParams[0])
......@@ -75,9 +76,9 @@ func (iai *ImageActionIIIF) Do(w http.ResponseWriter, req *http.Request, me *Med
ext = "jpg"
}
sizePrefix := "!"
if _, ok := ps["stretch"]; ok {
sizePrefix = ""
// if not stretch, we need !size
if _, ok := ps["stretch"]; !ok {
size = "!" + size
}
resultName := fmt.Sprintf("%s_%vx%v.%s", me.Signature, width, height, ext)
......@@ -85,26 +86,32 @@ func (iai *ImageActionIIIF) Do(w http.ResponseWriter, req *http.Request, me *Med
// build param string
var paramstring string
region := "full"
if _, ok := ps["crop"]; ok {
// for cropping in the middle, we need region parameters
aspectOrig := float64(me.Width) / float64(me.Height)
aspectNew := float64(width) / float64(height)
var nX, nY, nW, nH int64
if aspectOrig > aspectNew {
// target is smaller than source - vertical fill
nY = 0
nH = me.Height
nW = int64(float64(nH) * aspectNew)
nX = (me.Width - nW) / 2
} else {
// source is smaller than target - horizontal fill
nX = 0
nW = me.Width
nH = int64(float64(nW) / aspectNew)
nY = (me.Height - nH) / 2
}
paramstring = fmt.Sprintf("%v,%v,%v,%v/%s%v,%v/0/default.%s", nX, nY, nW, nH, sizePrefix, width, height, ext)
} else {
paramstring = fmt.Sprintf("full/%s%v,%v/0/default.%s", sizePrefix, width, height, ext)
region = fmt.Sprintf("%v,%v,%v,%v", nX, nY, nW, nH)
}
// todo: region & rotation parameter
paramstring = fmt.Sprintf("%s/%v/0/default.%s", region, size, ext)
sigfile := iai.ms.fspool.Truename(me.URI)
sigfile = strings.TrimPrefix(sigfile, iai.ms.iiifBase)
sigfile = strings.Replace(sigfile, "/", "%24", -1)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment