Merge pull request #96 from greut/rot45

Add support for 45° rotation.
master
Tomás Aparicio 9 years ago committed by GitHub
commit ba94508be7

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB

@ -57,12 +57,20 @@ type Angle int
const (
// D0 represents the rotation angle 0 degrees.
D0 Angle = 0
// D45 represents the rotation angle 90 degrees.
D45 Angle = 45
// D90 represents the rotation angle 90 degrees.
D90 Angle = 90
// D135 represents the rotation angle 90 degrees.
D135 Angle = 135
// D180 represents the rotation angle 180 degrees.
D180 Angle = 180
// D180 represents the rotation angle 180 degrees.
D235 Angle = 235
// D270 represents the rotation angle 270 degrees.
D270 Angle = 270
// D315 represents the rotation angle 180 degrees.
D315 Angle = 315
)
// Direction represents the image direction value.

@ -121,16 +121,32 @@ int
vips_rotate(VipsImage *in, VipsImage **out, int angle) {
int rotate = VIPS_ANGLE_D0;
if (angle == 90) {
angle %= 360;
if (angle == 45) {
rotate = VIPS_ANGLE45_D45;
} else if (angle == 90) {
rotate = VIPS_ANGLE_D90;
} else if (angle == 135) {
rotate = VIPS_ANGLE45_D135;
} else if (angle == 180) {
rotate = VIPS_ANGLE_D180;
} else if (angle == 225) {
rotate = VIPS_ANGLE45_D225;
} else if (angle == 270) {
rotate = VIPS_ANGLE_D270;
} else if (angle == 315) {
rotate = VIPS_ANGLE45_D315;
} else {
angle = 0;
}
if (angle > 0 && angle % 90 != 0) {
return vips_rot45(in, out, "angle", rotate, NULL);
} else {
return vips_rot(in, out, rotate, NULL);
}
}
int
vips_exif_orientation(VipsImage *image) {

@ -42,11 +42,20 @@ func TestVipsSave(t *testing.T) {
}
func TestVipsRotate(t *testing.T) {
image, _, _ := vipsRead(readImage("test.jpg"))
files := []struct {
name string
rotate Angle
}{
{"test.jpg", D90},
{"test_square.jpg", D45},
}
newImg, err := vipsRotate(image, D90)
for _, file := range files {
image, _, _ := vipsRead(readImage(file.name))
newImg, err := vipsRotate(image, file.rotate)
if err != nil {
t.Fatal("Cannot save the image")
t.Fatal("Cannot rotate the image")
}
buf, _ := vipsSave(newImg, vipsSaveOptions{Quality: 95})
@ -54,6 +63,7 @@ func TestVipsRotate(t *testing.T) {
t.Fatal("Empty image")
}
}
}
func TestVipsZoom(t *testing.T) {
image, _, _ := vipsRead(readImage("test.jpg"))

Loading…
Cancel
Save