From f335ee2989d63385d392fa8b18f2e728bf47e841 Mon Sep 17 00:00:00 2001 From: Nicholas Rawlings Date: Fri, 6 Mar 2015 13:47:44 -0500 Subject: [PATCH 1/3] Add support for image rotation --- shear.go | 8 ++++++++ shear.h | 6 ++++++ shear_gm.c | 11 +++++++++++ shear_im.c | 11 +++++++++++ 4 files changed, 36 insertions(+) create mode 100644 shear.h create mode 100644 shear_gm.c create mode 100644 shear_im.c diff --git a/shear.go b/shear.go index f41c387..edcb966 100644 --- a/shear.go +++ b/shear.go @@ -2,6 +2,7 @@ package magick // #include // #include "bridge.h" +// #include "shear.h" import "C" // AffineTransform returns a new image created by transforming @@ -9,3 +10,10 @@ import "C" func (im *Image) AffineTransform(m *AffineMatrix) (*Image, error) { return im.applyDataFunc("transforming (affine)", C.ImageDataFunc(C.AffineTransformImage), m.matrix()) } + +// Rotate creates a new image that is a rotated copy of an existing one. Positive angles rotate counter-clockwise (right-hand rule), while negative angles rotate clockwise. +func (im *Image) Rotate(degrees float64) (*Image, error) { + data := C.double(degrees) + return im.applyDataFunc("rotating", C.ImageDataFunc(C.rotateImage), &data) +} + \ No newline at end of file diff --git a/shear.h b/shear.h new file mode 100644 index 0000000..0fb548c --- /dev/null +++ b/shear.h @@ -0,0 +1,6 @@ +#ifndef SHEAR_H +#define SHEAR_H + +Image * rotateImage(Image *image, void *data, ExceptionInfo *ex); + +#endif diff --git a/shear_gm.c b/shear_gm.c new file mode 100644 index 0000000..7c940d7 --- /dev/null +++ b/shear_gm.c @@ -0,0 +1,11 @@ +// +build gm + +#include +#include "shear.h" + +Image * +rotateImage(Image *image, void *data, ExceptionInfo *ex) +{ + double *d = data; + return RotateImage(image, *d, ex); +} diff --git a/shear_im.c b/shear_im.c new file mode 100644 index 0000000..6069b71 --- /dev/null +++ b/shear_im.c @@ -0,0 +1,11 @@ +// +build !gm + +#include +#include "shear.h" + +Image * +rotateImage(Image *image, void *data, ExceptionInfo *ex) +{ + double *d = data; + return ShearRotateImage(image, *d, ex); +} From 88a7b7c5035f71b6ffc16f0a34b95a3dc5abbf98 Mon Sep 17 00:00:00 2001 From: Nicholas Rawlings Date: Fri, 6 Mar 2015 15:24:43 -0500 Subject: [PATCH 2/3] Add strip method --- image.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/image.go b/image.go index 4f3c8be..5279855 100644 --- a/image.go +++ b/image.go @@ -65,6 +65,12 @@ func (im *Image) Delay() int { return int(im.image.delay) } +// Strip removes all profiles and text attributes from the image. +func (im *Image) Strip() bool { + success := int(C.StripImage(im.image)) + return success > 0 +} + // Clone returns a copy of the image. If the image // has multiple frames, it copies all of them. To // Clone just one frame use im.Frame(i).Clone(). From 98d0f490e6df18ddad77ff1647ceed0e42d91f51 Mon Sep 17 00:00:00 2001 From: Nicholas Rawlings Date: Fri, 13 Mar 2015 18:14:31 -0400 Subject: [PATCH 3/3] Apply ImageRotate to each frame separately when using GM --- shear.go | 7 ------- shear_gm.go | 34 ++++++++++++++++++++++++++++++++++ shear_im.go | 15 +++++++++++++++ 3 files changed, 49 insertions(+), 7 deletions(-) create mode 100644 shear_gm.go create mode 100644 shear_im.go diff --git a/shear.go b/shear.go index edcb966..b5a52fb 100644 --- a/shear.go +++ b/shear.go @@ -10,10 +10,3 @@ import "C" func (im *Image) AffineTransform(m *AffineMatrix) (*Image, error) { return im.applyDataFunc("transforming (affine)", C.ImageDataFunc(C.AffineTransformImage), m.matrix()) } - -// Rotate creates a new image that is a rotated copy of an existing one. Positive angles rotate counter-clockwise (right-hand rule), while negative angles rotate clockwise. -func (im *Image) Rotate(degrees float64) (*Image, error) { - data := C.double(degrees) - return im.applyDataFunc("rotating", C.ImageDataFunc(C.rotateImage), &data) -} - \ No newline at end of file diff --git a/shear_gm.go b/shear_gm.go new file mode 100644 index 0000000..e560476 --- /dev/null +++ b/shear_gm.go @@ -0,0 +1,34 @@ +// +build gm + +package magick + +// #include +// #include "bridge.h" +// #include "shear.h" +import "C" + +// Rotate creates a new image that is a rotated copy of an existing one. Positive angles rotate counter-clockwise (right-hand rule), while negative angles rotate clockwise. +func (im *Image) Rotate(degrees float64) (*Image, error) { + data := C.double(degrees) + frames := im.NFrames() + newImage, err := im.First().applyDataFunc("rotating", C.ImageDataFunc(C.rotateImage), &data) + if err != nil { + return nil, err + } + for i := 1; i < frames; i++ { + frame, err := im.Frame(i) + if err != nil { + return nil, err + } + newFrame, err := frame.applyDataFunc("rotating", C.ImageDataFunc(C.rotateImage), &data) + if err != nil { + return nil, err + } + err = newImage.Append(newFrame) + if err != nil { + return nil, err + } + } + return newImage.Coalesce() +} + \ No newline at end of file diff --git a/shear_im.go b/shear_im.go new file mode 100644 index 0000000..fcbbe8a --- /dev/null +++ b/shear_im.go @@ -0,0 +1,15 @@ +// +build !gm + +package magick + +// #include +// #include "bridge.h" +// #include "shear.h" +import "C" + +// Rotate creates a new image that is a rotated copy of an existing one. Positive angles rotate counter-clockwise (right-hand rule), while negative angles rotate clockwise. +func (im *Image) Rotate(degrees float64) (*Image, error) { + data := C.double(degrees) + return im.applyDataFunc("rotating", C.ImageDataFunc(C.rotateImage), &data) +} + \ No newline at end of file