Adding trim operation.

Closes #22

Signed-off-by: Yoan Blanc <yoan@dosimple.ch>
This commit is contained in:
Yoan Blanc 2017-09-12 10:36:34 -04:00
parent b35675c245
commit c1f2667c0f
No known key found for this signature in database
GPG key ID: 6058CF4574298812
8 changed files with 64 additions and 5 deletions

View file

@ -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