Skip to content

Commit

Permalink
Merge branch 'im7_SetImageMask' into im-7
Browse files Browse the repository at this point in the history
  • Loading branch information
justinfx committed Apr 25, 2021
2 parents 5e70d93 + 60ac9c2 commit 5c47103
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
12 changes: 12 additions & 0 deletions imagick/magick_wand_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ package imagick
#include <unistd.h>
#include <MagickCore/MagickCore.h>
#include <MagickWand/MagickWand.h>
// declare symbols only defined in C source and not in header
WandExport MagickBooleanType MagickSetImageMask(
MagickWand *wand, const PixelMask type, const MagickWand *clip_mask
);
*/
import "C"

Expand Down Expand Up @@ -2357,6 +2362,13 @@ func (mw *MagickWand) SetImageMatte(matte bool) error {
return mw.getLastErrorIfFailed(ok)
}

// Sets image clip mask.
// PixelMaskType can be one of: PIXEL_MASK_READ, PIXEL_MASK_WRITE
func (mw *MagickWand) SetImageMask(typ PixelMaskType, clipMask *MagickWand) error {
ok := C.MagickSetImageMask(mw.mw, C.PixelMask(typ), clipMask.mw)
return mw.getLastErrorIfFailed(ok)
}

// Sets the image orientation.
func (mw *MagickWand) SetImageOrientation(orientation OrientationType) error {
ok := C.MagickSetImageOrientation(mw.mw, C.OrientationType(orientation))
Expand Down
16 changes: 16 additions & 0 deletions imagick/magick_wand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,22 @@ func TestImageAlpha(t *testing.T) {
}
}

func TestImageMask(t *testing.T) {
mw := NewMagickWand()
mw.ReadImage(`logo:`)

mask := NewMagickWand()
mask.ReadImage(`logo:`)

if err := mw.SetImageMask(PIXEL_MASK_READ, mask); err != nil {
t.Fatal(err)
}
if err := mw.SetImageMask(PIXEL_MASK_WRITE, mask); err != nil {
t.Fatal(err)
}

}

func TestImageChannelMask(t *testing.T) {
mw := NewMagickWand()
mw.ReadImage(`logo:`)
Expand Down
19 changes: 19 additions & 0 deletions imagick/pixel_mask_type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2013 Herbert G. Fischer. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package imagick

/*
#include <MagickWand/MagickWand.h>
*/
import "C"

type PixelMaskType int

const (
PIXEL_MASK_UNDEFINED PixelMaskType = C.UndefinedPixelMask
PIXEL_MASK_READ PixelMaskType = C.ReadPixelMask
PIXEL_MASK_WRITE PixelMaskType = C.WritePixelMask
PIXEL_MASK_COMPOSITE PixelMaskType = C.CompositePixelMask
)

0 comments on commit 5c47103

Please sign in to comment.