Add support for 45° rotation.

master
Yoan Blanc 9 years ago
parent 66f3ccc217
commit 00fee003f7
No known key found for this signature in database
GPG Key ID: 6058CF4574298812

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB

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

@ -121,15 +121,31 @@ int
vips_rotate(VipsImage *in, VipsImage **out, int angle) { vips_rotate(VipsImage *in, VipsImage **out, int angle) {
int rotate = VIPS_ANGLE_D0; 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; rotate = VIPS_ANGLE_D90;
} else if (angle == 135) {
rotate = VIPS_ANGLE45_D135;
} else if (angle == 180) { } else if (angle == 180) {
rotate = VIPS_ANGLE_D180; rotate = VIPS_ANGLE_D180;
} else if (angle == 225) {
rotate = VIPS_ANGLE45_D225;
} else if (angle == 270) { } else if (angle == 270) {
rotate = VIPS_ANGLE_D270; 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); return vips_rot(in, out, rotate, NULL);
}
} }
int int

@ -42,17 +42,27 @@ func TestVipsSave(t *testing.T) {
} }
func TestVipsRotate(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 { if err != nil {
t.Fatal("Cannot save the image") t.Fatal("Cannot rotate the image")
} }
buf, _ := vipsSave(newImg, vipsSaveOptions{Quality: 95}) buf, _ := vipsSave(newImg, vipsSaveOptions{Quality: 95})
if len(buf) == 0 { if len(buf) == 0 {
t.Fatal("Empty image") t.Fatal("Empty image")
} }
}
} }
func TestVipsZoom(t *testing.T) { func TestVipsZoom(t *testing.T) {

Loading…
Cancel
Save