feat(core): support bimg@1.0.5, support extend background param
This commit is contained in:
parent
26a7ca9b16
commit
7da4696197
|
@ -1,6 +1,6 @@
|
|||
# Start from a Debian image with the latest version of Go installed
|
||||
# and a workspace (GOPATH) configured at /go.
|
||||
FROM marcbachmann/libvips
|
||||
FROM marcbachmann/libvips:latest
|
||||
MAINTAINER tomas@aparicio.me
|
||||
|
||||
# Server port to listen
|
||||
|
|
45
README.md
45
README.md
|
@ -412,12 +412,22 @@ Image measures are always in pixels, unless otherwise indicated.
|
|||
- **url** `string` - Fetch the image from a remove HTTP server. In order to use this you must pass the `-enable-url-source` flag.
|
||||
- **colorspace** `string` - Use a custom color space for the output image. Allowed values are: `srgb` or `bw` (black&white)
|
||||
- **field** `string` - Custom image form field name if using `multipart/form`. Defaults to: `file`
|
||||
- **extend** `string` - Extend represents the image extend mode used when the edges of an image are extended. Allowed values are: `black`, `copy`, `mirror`, `white` and `background`. If `background` value is specified, you can define the desired extend RGB color via `background` param, such as `?extend=background&background=250,20,10`. For more info, see [libvips docs](http://www.vips.ecs.soton.ac.uk/supported/8.4/doc/html/libvips/libvips-conversion.html#VIPS-EXTEND-BACKGROUND:CAPS).
|
||||
- **background** `string` - Background RGB decimal base color to use when flattening transparent PNGs. Example: `255,200,150`
|
||||
|
||||
#### GET /
|
||||
Content-Type: `application/json`
|
||||
|
||||
Serves as JSON the current imaginary, bimg and libvips versions.
|
||||
Serves as JSON the current `imaginary`, `bimg` and `libvips` versions.
|
||||
|
||||
Example response:
|
||||
```json
|
||||
{
|
||||
"imaginary": "0.1.28",
|
||||
"bimg": "1.0.5",
|
||||
"libvips": "8.4.1"
|
||||
}
|
||||
```
|
||||
|
||||
#### GET /health
|
||||
Content-Type: `application/json`
|
||||
|
@ -479,10 +489,13 @@ Crop the image by a given width or height. Image ratio is maintained
|
|||
- url `string` - Only GET method and if the `-enable-url-source` flag is present
|
||||
- force `bool`
|
||||
- rotate `int`
|
||||
- embed `bool`
|
||||
- norotation `bool`
|
||||
- noprofile `bool`
|
||||
- flip `bool`
|
||||
- flop `bool`
|
||||
- extend `string`
|
||||
- background `string` - Example: `?background=250,20,10`
|
||||
- colorspace `string`
|
||||
- gravity `string`
|
||||
- field `string` - Only POST and `multipart/form` payloads
|
||||
|
@ -501,12 +514,15 @@ Resize an image by width or height. Image aspect ratio is maintained
|
|||
- type `string`
|
||||
- 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
|
||||
- embed `bool`
|
||||
- force `bool`
|
||||
- rotate `int`
|
||||
- norotation `bool`
|
||||
- noprofile `bool`
|
||||
- flip `bool`
|
||||
- flop `bool`
|
||||
- extend `string`
|
||||
- background `string` - Example: `?background=250,20,10`
|
||||
- colorspace `string`
|
||||
- field `string` - Only POST and `multipart/form` payloads
|
||||
|
||||
|
@ -522,12 +538,15 @@ Accepts: `image/*, multipart/form-data`. Content-Type: `image/*`
|
|||
- type `string`
|
||||
- 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
|
||||
- embed `bool`
|
||||
- force `bool`
|
||||
- rotate `int`
|
||||
- norotation `bool`
|
||||
- noprofile `bool`
|
||||
- flip `bool`
|
||||
- flop `bool`
|
||||
- extend `string`
|
||||
- background `string` - Example: `?background=250,20,10`
|
||||
- colorspace `string`
|
||||
- field `string` - Only POST and `multipart/form` payloads
|
||||
|
||||
|
@ -547,12 +566,15 @@ Accepts: `image/*, multipart/form-data`. Content-Type: `image/*`
|
|||
- type `string`
|
||||
- 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
|
||||
- embed `bool`
|
||||
- force `bool`
|
||||
- rotate `int`
|
||||
- norotation `bool`
|
||||
- noprofile `bool`
|
||||
- flip `bool`
|
||||
- flop `bool`
|
||||
- extend `string`
|
||||
- background `string` - Example: `?background=250,20,10`
|
||||
- colorspace `string`
|
||||
- field `string` - Only POST and `multipart/form` payloads
|
||||
|
||||
|
@ -569,12 +591,15 @@ Accepts: `image/*, multipart/form-data`. Content-Type: `image/*`
|
|||
- type `string`
|
||||
- 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
|
||||
- embed `bool`
|
||||
- force `bool`
|
||||
- rotate `int`
|
||||
- norotation `bool`
|
||||
- noprofile `bool`
|
||||
- flip `bool`
|
||||
- flop `bool`
|
||||
- extend `string`
|
||||
- background `string` - Example: `?background=250,20,10`
|
||||
- colorspace `string`
|
||||
- field `string` - Only POST and `multipart/form` payloads
|
||||
|
||||
|
@ -590,12 +615,15 @@ Accepts: `image/*, multipart/form-data`. Content-Type: `image/*`
|
|||
- type `string`
|
||||
- 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
|
||||
- embed `bool`
|
||||
- force `bool`
|
||||
- rotate `int`
|
||||
- norotation `bool`
|
||||
- noprofile `bool`
|
||||
- flip `bool`
|
||||
- flop `bool`
|
||||
- extend `string`
|
||||
- background `string` - Example: `?background=250,20,10`
|
||||
- colorspace `string`
|
||||
- field `string` - Only POST and `multipart/form` payloads
|
||||
|
||||
|
@ -612,11 +640,14 @@ Accepts: `image/*, multipart/form-data`. Content-Type: `image/*`
|
|||
- type `string`
|
||||
- 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
|
||||
- embed `bool`
|
||||
- force `bool`
|
||||
- norotation `bool`
|
||||
- noprofile `bool`
|
||||
- flip `bool`
|
||||
- flop `bool`
|
||||
- extend `string`
|
||||
- background `string` - Example: `?background=250,20,10`
|
||||
- colorspace `string`
|
||||
- field `string` - Only POST and `multipart/form` payloads
|
||||
|
||||
|
@ -632,11 +663,14 @@ Accepts: `image/*, multipart/form-data`. Content-Type: `image/*`
|
|||
- type `string`
|
||||
- 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
|
||||
- embed `bool`
|
||||
- force `bool`
|
||||
- norotation `bool`
|
||||
- noprofile `bool`
|
||||
- flip `bool`
|
||||
- flop `bool`
|
||||
- extend `string`
|
||||
- background `string` - Example: `?background=250,20,10`
|
||||
- colorspace `string`
|
||||
- field `string` - Only POST and `multipart/form` payloads
|
||||
|
||||
|
@ -652,11 +686,14 @@ Accepts: `image/*, multipart/form-data`. Content-Type: `image/*`
|
|||
- type `string`
|
||||
- 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
|
||||
- embed `bool`
|
||||
- force `bool`
|
||||
- norotation `bool`
|
||||
- noprofile `bool`
|
||||
- flip `bool`
|
||||
- flop `bool`
|
||||
- extend `string`
|
||||
- background `string` - Example: `?background=250,20,10`
|
||||
- colorspace `string`
|
||||
- field `string` - Only POST and `multipart/form` payloads
|
||||
|
||||
|
@ -670,12 +707,15 @@ Accepts: `image/*, multipart/form-data`. Content-Type: `image/*`
|
|||
- compression `int` (PNG-only)
|
||||
- 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
|
||||
- embed `bool`
|
||||
- force `bool`
|
||||
- rotate `int`
|
||||
- norotation `bool`
|
||||
- noprofile `bool`
|
||||
- flip `bool`
|
||||
- flop `bool`
|
||||
- extend `string`
|
||||
- background `string` - Example: `?background=250,20,10`
|
||||
- colorspace `string`
|
||||
- field `string` - Only POST and `multipart/form` payloads
|
||||
|
||||
|
@ -697,12 +737,15 @@ Accepts: `image/*, multipart/form-data`. Content-Type: `image/*`
|
|||
- type `string`
|
||||
- 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
|
||||
- embed `bool`
|
||||
- force `bool`
|
||||
- rotate `int`
|
||||
- norotation `bool`
|
||||
- noprofile `bool`
|
||||
- flip `bool`
|
||||
- flop `bool`
|
||||
- extend `string`
|
||||
- background `string` - Example: `?background=250,20,10`
|
||||
- colorspace `string`
|
||||
- field `string` - Only POST and `multipart/form` payloads
|
||||
|
||||
|
|
4
app.json
4
app.json
|
@ -6,7 +6,9 @@
|
|||
"processing",
|
||||
"go",
|
||||
"microservice",
|
||||
"api"
|
||||
"api",
|
||||
"libvips",
|
||||
"vips"
|
||||
],
|
||||
"repository": "https://github.com/h2non/imaginary",
|
||||
"logo": "https://camo.githubusercontent.com/bcb3b2bd343c3c85aaf6094e51c6178bbe239a32/687474703a2f2f7331342e706f7374696d672e6f72672f3874683731613230312f696d6167696e6172795f776f726c642e6a7067",
|
||||
|
|
12
options.go
12
options.go
|
@ -20,6 +20,7 @@ type ImageOptions struct {
|
|||
Flip bool
|
||||
Flop bool
|
||||
Force bool
|
||||
Embed bool
|
||||
NoCrop bool
|
||||
NoReplicate bool
|
||||
NoRotation bool
|
||||
|
@ -29,6 +30,7 @@ type ImageOptions struct {
|
|||
Font string
|
||||
Type string
|
||||
Color []uint8
|
||||
Extend bimg.Extend
|
||||
Gravity bimg.Gravity
|
||||
Colorspace bimg.Interpretation
|
||||
Background []uint8
|
||||
|
@ -36,7 +38,7 @@ type ImageOptions struct {
|
|||
|
||||
// BimgOptions creates a new bimg compatible options struct mapping the fields properly
|
||||
func BimgOptions(o ImageOptions) bimg.Options {
|
||||
return bimg.Options{
|
||||
opts := bimg.Options{
|
||||
Width: o.Width,
|
||||
Height: o.Height,
|
||||
Flip: o.Flip,
|
||||
|
@ -47,8 +49,16 @@ func BimgOptions(o ImageOptions) bimg.Options {
|
|||
NoProfile: o.NoProfile,
|
||||
Force: o.Force,
|
||||
Gravity: o.Gravity,
|
||||
Embed: o.Embed,
|
||||
Extend: o.Extend,
|
||||
Interpretation: o.Colorspace,
|
||||
Type: ImageType(o.Type),
|
||||
Rotate: bimg.Angle(o.Rotate),
|
||||
}
|
||||
|
||||
if len(o.Background) != 0 {
|
||||
opts.Background = bimg.Color{o.Background[0], o.Background[1], o.Background[2]}
|
||||
}
|
||||
|
||||
return opts
|
||||
}
|
||||
|
|
24
params.go
24
params.go
|
@ -31,6 +31,7 @@ var allowedParams = map[string]string{
|
|||
"norotation": "bool",
|
||||
"noreplicate": "bool",
|
||||
"force": "bool",
|
||||
"embed": "bool",
|
||||
"text": "string",
|
||||
"font": "string",
|
||||
"type": "string",
|
||||
|
@ -38,6 +39,7 @@ var allowedParams = map[string]string{
|
|||
"colorspace": "colorspace",
|
||||
"gravity": "gravity",
|
||||
"background": "color",
|
||||
"extend": "extend",
|
||||
}
|
||||
|
||||
func readParams(query url.Values) ImageOptions {
|
||||
|
@ -70,6 +72,9 @@ func parseParam(param, kind string) interface{} {
|
|||
if kind == "bool" {
|
||||
return parseBool(param)
|
||||
}
|
||||
if kind == "extend" {
|
||||
return parseExtendMode(param)
|
||||
}
|
||||
return param
|
||||
}
|
||||
|
||||
|
@ -93,12 +98,14 @@ func mapImageParams(params map[string]interface{}) ImageOptions {
|
|||
Type: params["type"].(string),
|
||||
Flip: params["flip"].(bool),
|
||||
Flop: params["flop"].(bool),
|
||||
Embed: params["flop"].(bool),
|
||||
NoCrop: params["nocrop"].(bool),
|
||||
Force: params["force"].(bool),
|
||||
NoReplicate: params["noreplicate"].(bool),
|
||||
NoRotation: params["norotation"].(bool),
|
||||
NoProfile: params["noprofile"].(bool),
|
||||
Opacity: float32(params["opacity"].(float64)),
|
||||
Extend: params["extend"].(bimg.Extend),
|
||||
Gravity: params["gravity"].(bimg.Gravity),
|
||||
Colorspace: params["colorspace"].(bimg.Interpretation),
|
||||
Background: params["background"].([]uint8),
|
||||
|
@ -138,6 +145,23 @@ func parseColor(val string) []uint8 {
|
|||
return buf
|
||||
}
|
||||
|
||||
func parseExtendMode(val string) bimg.Extend {
|
||||
val = strings.TrimSpace(strings.ToLower(val))
|
||||
if val == "white" {
|
||||
return bimg.ExtendWhite
|
||||
}
|
||||
if val == "copy" {
|
||||
return bimg.ExtendCopy
|
||||
}
|
||||
if val == "mirror" {
|
||||
return bimg.ExtendMirror
|
||||
}
|
||||
if val == "background" {
|
||||
return bimg.ExtendBackground
|
||||
}
|
||||
return bimg.ExtendBlack
|
||||
}
|
||||
|
||||
func parseGravity(val string) bimg.Gravity {
|
||||
val = strings.TrimSpace(strings.ToLower(val))
|
||||
if val == "south" {
|
||||
|
|
Loading…
Reference in New Issue