|
@@ -275,16 +275,6 @@ func (g *Gateway) injectImageLibFunctions(vm *otto.Otto, u *user.User, scriptFsh
|
|
g.raiseError(err)
|
|
g.raiseError(err)
|
|
return otto.FalseValue()
|
|
return otto.FalseValue()
|
|
}
|
|
}
|
|
- destWritePath := rdest
|
|
|
|
- var destCloserFunction func()
|
|
|
|
- if destFsh.RequireBuffer {
|
|
|
|
- destWritePath, destCloserFunction = g.getUserSpecificTempFilePath(u, rdest)
|
|
|
|
- if err != nil {
|
|
|
|
- g.raiseError(err)
|
|
|
|
- return otto.FalseValue()
|
|
|
|
- }
|
|
|
|
- defer destCloserFunction()
|
|
|
|
- }
|
|
|
|
|
|
|
|
//Try to read the source image
|
|
//Try to read the source image
|
|
imageBytes, err := srcFshAbs.ReadFile(rsrc)
|
|
imageBytes, err := srcFshAbs.ReadFile(rsrc)
|
|
@@ -308,16 +298,33 @@ func (g *Gateway) injectImageLibFunctions(vm *otto.Otto, u *user.User, scriptFsh
|
|
Mode: cutter.TopLeft,
|
|
Mode: cutter.TopLeft,
|
|
})
|
|
})
|
|
|
|
|
|
- //Create the new image
|
|
|
|
- out, err := os.Create(destWritePath)
|
|
|
|
- if err != nil {
|
|
|
|
- g.raiseError(err)
|
|
|
|
- return otto.FalseValue()
|
|
|
|
|
|
+ //Create the output file
|
|
|
|
+ var out arozfs.File
|
|
|
|
+ destWritePath := ""
|
|
|
|
+ if destFsh.RequireBuffer {
|
|
|
|
+ destWritePath, _ = g.getUserSpecificTempFilePath(u, rdest)
|
|
|
|
+
|
|
|
|
+ //Create the new image in buffer file
|
|
|
|
+ out, err = os.Create(destWritePath)
|
|
|
|
+ if err != nil {
|
|
|
|
+ g.raiseError(err)
|
|
|
|
+ return otto.FalseValue()
|
|
|
|
+ }
|
|
|
|
+ defer out.Close()
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+ //Create the target file via FSA
|
|
|
|
+ out, err = destFsh.FileSystemAbstraction.Create(rdest)
|
|
|
|
+ if err != nil {
|
|
|
|
+ g.raiseError(err)
|
|
|
|
+ return otto.FalseValue()
|
|
|
|
+ }
|
|
|
|
+ defer out.Close()
|
|
}
|
|
}
|
|
|
|
|
|
- if strings.ToLower(filepath.Ext(destWritePath)) == ".png" {
|
|
|
|
|
|
+ if strings.ToLower(filepath.Ext(rdest)) == ".png" {
|
|
png.Encode(out, croppedImg)
|
|
png.Encode(out, croppedImg)
|
|
- } else if strings.ToLower(filepath.Ext(destWritePath)) == ".jpg" {
|
|
|
|
|
|
+ } else if strings.ToLower(filepath.Ext(rdest)) == ".jpg" {
|
|
jpeg.Encode(out, croppedImg, nil)
|
|
jpeg.Encode(out, croppedImg, nil)
|
|
} else {
|
|
} else {
|
|
g.raiseError(errors.New("Not supported format: Only support jpg or png"))
|
|
g.raiseError(errors.New("Not supported format: Only support jpg or png"))
|