Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,14 @@ Accepts: `image/*, multipart/form-data`. Content-Type: `image/*`
- minampl `float`
- field `string` - Only POST and `multipart/form` payloads

#### GET | POST /autorotate
Accepts: `image/*, multipart/form-data`. Content-Type: `image/*`

##### Allowed params

- file `string` - Only GET method and if the `-mount` flag is present
- url `string` - Only GET method and if the `-enable-url-source` flag is present

#### GET | POST /flip
Accepts: `image/*, multipart/form-data`. Content-Type: `image/*`

Expand Down
1 change: 1 addition & 0 deletions controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func formController(w http.ResponseWriter, r *http.Request) {
{"Extract", "extract", "top=100&left=100&areawidth=300&areaheight=150"},
{"Enlarge", "enlarge", "width=1440&height=900&quality=95"},
{"Rotate", "rotate", "rotate=180"},
{"Autorotate", "autorotate", ""},
{"Flip", "flip", ""},
{"Flop", "flop", ""},
{"Thumbnail", "thumbnail", "width=100"},
Expand Down
25 changes: 25 additions & 0 deletions image.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,31 @@ func Rotate(buf []byte, o ImageOptions) (Image, error) {
return Process(buf, opts)
}

func AutoRotate(buf []byte, o ImageOptions) (out Image, err error) {
opts := BimgOptions(o)
defer func() {
if r := recover(); r != nil {
switch value := r.(type) {
case error:
err = value
case string:
err = errors.New(value)
default:
err = errors.New("libvips internal error")
}
out = Image{}
}
}()

buf, err = bimg.AutoRotate(buf, opts)
if err != nil {
return Image{}, err
}

mime := GetImageMimeType(bimg.DetermineImageType(buf))
return Image{Body: buf, Mime: mime}, nil
}

func Flip(buf []byte, o ImageOptions) (Image, error) {
opts := BimgOptions(o)
opts.Flip = true
Expand Down
1 change: 1 addition & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func NewServerMux(o ServerOptions) http.Handler {
mux.Handle(join(o, "/extract"), image(Extract))
mux.Handle(join(o, "/crop"), image(Crop))
mux.Handle(join(o, "/rotate"), image(Rotate))
mux.Handle(join(o, "/autorotate"), image(AutoRotate))
mux.Handle(join(o, "/flip"), image(Flip))
mux.Handle(join(o, "/flop"), image(Flop))
mux.Handle(join(o, "/thumbnail"), image(Thumbnail))
Expand Down