Skip to content

Commit

Permalink
Added SetImageType method
Browse files Browse the repository at this point in the history
  • Loading branch information
aliksend committed Jan 11, 2016
1 parent 2d6532d commit 726b17e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# About

This is a fork of [github.com/quirkey/magick](http://github.com/quirkey/magick) with `Colorspace(...)` support
This is a fork of [github.com/quirkey/magick](http://github.com/quirkey/magick) with `Colorspace(...)` and `SetImageType(...)` support

# magick

Expand Down
24 changes: 24 additions & 0 deletions magick.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,21 @@ const (
YPBPR Colorspace = C.YPbPrColorspace
)

type ImageType C.ImageType

const (
BilevelType ImageType = C.BilevelType
GrayscaleType ImageType = C.GrayscaleType
GrayscaleMatteType ImageType = C.GrayscaleMatteType
PaletteType ImageType = C.PaletteType
PaletteMatteType ImageType = C.PaletteMatteType
TrueColorType ImageType = C.TrueColorType
TrueColorMatteType ImageType = C.TrueColorMatteType
ColorSeparationType ImageType = C.ColorSeparationType
ColorSeparationMatteType ImageType = C.ColorSeparationMatteType
OptimizeType ImageType = C.OptimizeType
)

func (err *MagickError) Error() string {
return "MagickError " + err.Severity + ": " + err.Reason + "- " + err.Description
}
Expand Down Expand Up @@ -351,6 +366,15 @@ func (im *MagickImage) Colorspace(cs Colorspace) (err error) {
return
}

func (im *MagickImage) SetImageType(tp ImageType) (err error) {
c_img_type := C.ImageType(tp)
ok := C.SetImageType(im.Image, c_img_type)
if ok == C.MagickFalse {
return &MagickError{"error", "", "could not set image type"}
}
return
}

// ParseGeometryToRectangleInfo converts from a geometry string (WxH+X+Y) into a Magick
// RectangleInfo that contains the individual properties
func (im *MagickImage) ParseGeometryToRectangleInfo(geometry string) (info C.RectangleInfo, err error) {
Expand Down
12 changes: 12 additions & 0 deletions magick_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,18 @@ func TestColorspace(t *testing.T) {
assert.T(t, err == nil)
}

func TestSetImageType(t *testing.T) {
image := setupImage(t)
err := image.SetImageType(TrueColor)
assert.T(t, err == nil)
err := image.SetImageType(Grayscale)
assert.T(t, err == nil)
err := image.SetImageType(TrueColorMatte)
assert.T(t, err == nil)
err := image.SetImageType(GrayscaleMatte)
assert.T(t, err == nil)
}

func TestFullStack(t *testing.T) {
var err error
var filename string
Expand Down

0 comments on commit 726b17e

Please sign in to comment.