mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-18 03:36:33 -07:00
Adding trim operation.
Closes #22 Signed-off-by: Yoan Blanc <yoan@dosimple.ch>
This commit is contained in:
parent
b35675c245
commit
c1f2667c0f
8 changed files with 64 additions and 5 deletions
10
resizer.go
10
resizer.go
|
|
@ -175,7 +175,8 @@ func normalizeOperation(o *Options, inWidth, inHeight int) {
|
|||
|
||||
func shouldTransformImage(o Options, inWidth, inHeight int) bool {
|
||||
return o.Force || (o.Width > 0 && o.Width != inWidth) ||
|
||||
(o.Height > 0 && o.Height != inHeight) || o.AreaWidth > 0 || o.AreaHeight > 0
|
||||
(o.Height > 0 && o.Height != inHeight) || o.AreaWidth > 0 || o.AreaHeight > 0 ||
|
||||
o.Trim
|
||||
}
|
||||
|
||||
func shouldApplyEffects(o Options) bool {
|
||||
|
|
@ -268,7 +269,12 @@ func extractOrEmbedImage(image *C.VipsImage, o Options) (*C.VipsImage, error) {
|
|||
left, top := (o.Width-inWidth)/2, (o.Height-inHeight)/2
|
||||
image, err = vipsEmbed(image, left, top, o.Width, o.Height, o.Extend, o.Background)
|
||||
break
|
||||
|
||||
case o.Trim:
|
||||
left, top, width, height, err := vipsTrim(image)
|
||||
if err == nil {
|
||||
image, err = vipsExtract(image, left, top, width, height)
|
||||
}
|
||||
break
|
||||
case o.Top != 0 || o.Left != 0 || o.AreaWidth != 0 || o.AreaHeight != 0:
|
||||
if o.AreaWidth == 0 {
|
||||
o.AreaHeight = o.Width
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue