Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add image rotation and profile stripping #33

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand Down
1 change: 1 addition & 0 deletions shear.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package magick

// #include <magick/api.h>
// #include "bridge.h"
// #include "shear.h"
import "C"

// AffineTransform returns a new image created by transforming
Expand Down
6 changes: 6 additions & 0 deletions shear.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef SHEAR_H
#define SHEAR_H

Image * rotateImage(Image *image, void *data, ExceptionInfo *ex);

#endif
11 changes: 11 additions & 0 deletions shear_gm.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// +build gm

#include <magick/api.h>
#include "shear.h"

Image *
rotateImage(Image *image, void *data, ExceptionInfo *ex)
{
double *d = data;
return RotateImage(image, *d, ex);
}
34 changes: 34 additions & 0 deletions shear_gm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// +build gm

package magick

// #include <magick/api.h>
// #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()
}

11 changes: 11 additions & 0 deletions shear_im.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// +build !gm

#include <magick/api.h>
#include "shear.h"

Image *
rotateImage(Image *image, void *data, ExceptionInfo *ex)
{
double *d = data;
return ShearRotateImage(image, *d, ex);
}
15 changes: 15 additions & 0 deletions shear_im.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// +build !gm

package magick

// #include <magick/api.h>
// #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)
}