-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
73 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,31 @@ | ||
package engine | ||
|
||
import ( | ||
"errors" | ||
|
||
"imgserver/object" | ||
"imgserver/response" | ||
Logger "github.com/labstack/gommon/log" | ||
//Logger "github.com/labstack/gommon/log" | ||
"gopkg.in/h2non/bimg.v1" | ||
) | ||
|
||
type ImageEngine struct { | ||
parent *response.Response | ||
Input []byte | ||
parent *response.Response | ||
} | ||
|
||
func NewImageEngine (res *response.Response) *ImageEngine { | ||
return &ImageEngine{Input: res.Body, parent: res} | ||
} | ||
|
||
func (self *ImageEngine) Process(obj *object.FileObject) (*response.Response, error) { | ||
|
||
for i, trans := range obj.Transforms { | ||
Logger.Infof("Permoring i = %d trans = %s", i, trans.Name) | ||
} | ||
|
||
return response.NewError(400, errors.New("Not ready")), errors.New("Not ready") | ||
image := bimg.NewImage(self.Input) | ||
buf, err := image.Process(obj.Transforms.BimgOptions()) | ||
if err != nil { | ||
return response.NewError(500, err), err | ||
} | ||
res := response.New(200, buf) | ||
res.SetContentType("image/" + bimg.DetermineImageTypeName(buf)) | ||
return res, nil | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,57 @@ | ||
package transforms | ||
|
||
type Base struct { | ||
Name string | ||
Params map[string]interface{} | ||
import "gopkg.in/h2non/bimg.v1" | ||
|
||
|
||
type Transforms struct { | ||
Height int | ||
Width int | ||
AreaHeight int | ||
AreaWidth int | ||
Top int | ||
Left int | ||
Quality int | ||
Compression int | ||
Zoom int | ||
Crop bool | ||
Enlarge bool | ||
Embed bool | ||
Flip bool | ||
Flop bool | ||
Force bool | ||
NoAutoRotate bool | ||
NoProfile bool | ||
Interlace bool | ||
StripMetadata bool | ||
Trim bool | ||
|
||
NotEmpty bool | ||
} | ||
|
||
func (self *Transforms) ResizeT(size []int, enlarge bool) (*Transforms) { | ||
self.Width = size[0] | ||
self.Height = size[1] | ||
self.Enlarge = enlarge | ||
self.NotEmpty = true | ||
return self | ||
} | ||
|
||
func (self *Transforms) CropT(size []int, enlarge bool) (*Transforms) { | ||
self.Width = size[0] | ||
self.Height = size[1] | ||
self.Enlarge = enlarge | ||
self.Crop = true | ||
self.NotEmpty = true | ||
return self | ||
} | ||
|
||
func (self *Transforms) BimgOptions() (bimg.Options) { | ||
return bimg.Options{ | ||
Width: self.Width, | ||
Height: self.Height, | ||
Enlarge: self.Enlarge, | ||
Crop: self.Crop, | ||
} | ||
} | ||
|
||
|