feat(#20): support flop operation (interface broken, sorry im still beta)

master
Tomas Aparicio 11 years ago
parent 2d17baca0d
commit 414fe40c91

@ -43,6 +43,7 @@ The [install script](https://github.com/lovell/sharp/blob/master/preinstall.sh)
- Crop - Crop
- Rotate - Rotate
- Flip - Flip
- Flop
- Thumbnail - Thumbnail
- Extract area - Extract area
- Format conversion - Format conversion
@ -56,7 +57,7 @@ Here you can see some performance test comparisons for multiple scenarios:
- [libvips speed and memory usage](http://www.vips.ecs.soton.ac.uk/index.php?title=Speed_and_Memory_Use) - [libvips speed and memory usage](http://www.vips.ecs.soton.ac.uk/index.php?title=Speed_and_Memory_Use)
- [sharp performance tests](https://github.com/lovell/sharp#the-task) - [sharp performance tests](https://github.com/lovell/sharp#the-task)
#### bimg performance tests #### Benchmarks
Tested using Go 1.4 and libvips-7.42.3 in OSX i7 2.7Ghz Tested using Go 1.4 and libvips-7.42.3 in OSX i7 2.7Ghz
``` ```

@ -82,13 +82,13 @@ func (i *Image) Rotate(a Angle) ([]byte, error) {
// Flip the image about the vertical Y axis // Flip the image about the vertical Y axis
func (i *Image) Flip() ([]byte, error) { func (i *Image) Flip() ([]byte, error) {
options := Options{Flip: VERTICAL} options := Options{Flip: true}
return i.Process(options) return i.Process(options)
} }
// Flop the image about the horizontal X axis // Flop the image about the horizontal X axis
func (i *Image) Flop() ([]byte, error) { func (i *Image) Flop() ([]byte, error) {
options := Options{Flip: VERTICAL} options := Options{Flop: true}
return i.Process(options) return i.Process(options)
} }

@ -112,6 +112,14 @@ func TestImageFlip(t *testing.T) {
Write("fixtures/test_flip_out.jpg", buf) Write("fixtures/test_flip_out.jpg", buf)
} }
func TestImageFlop(t *testing.T) {
buf, err := initImage("test.jpg").Flop()
if err != nil {
t.Errorf("Cannot process the image: %#v", err)
}
Write("fixtures/test_flop_out.jpg", buf)
}
func TestImageRotate(t *testing.T) { func TestImageRotate(t *testing.T) {
buf, err := initImage("test_flip_out.jpg").Rotate(90) buf, err := initImage("test_flip_out.jpg").Rotate(90)
if err != nil { if err != nil {

@ -68,9 +68,10 @@ type Options struct {
Crop bool Crop bool
Enlarge bool Enlarge bool
Embed bool Embed bool
Flip bool
Flop bool
Type ImageType Type ImageType
Rotate Angle Rotate Angle
Flip Direction
Gravity Gravity Gravity Gravity
Interpolator Interpolator Interpolator Interpolator
} }

@ -160,10 +160,11 @@ func extractImage(image *C.struct__VipsImage, o Options) (*C.struct__VipsImage,
func rotateImage(image *C.struct__VipsImage, o Options) (*C.struct__VipsImage, error) { func rotateImage(image *C.struct__VipsImage, o Options) (*C.struct__VipsImage, error) {
var err error var err error
var direction Direction = -1
rotation, flip := calculateRotationAndFlip(image, o.Rotate) rotation, flip := calculateRotationAndFlip(image, o.Rotate)
if flip { if flip {
o.Flip = HORIZONTAL o.Flip = flip
} }
if rotation > D0 && o.Rotate == 0 { if rotation > D0 && o.Rotate == 0 {
o.Rotate = rotation o.Rotate = rotation
@ -172,8 +173,15 @@ func rotateImage(image *C.struct__VipsImage, o Options) (*C.struct__VipsImage, e
if o.Rotate > 0 { if o.Rotate > 0 {
image, err = vipsRotate(image, getAngle(o.Rotate)) image, err = vipsRotate(image, getAngle(o.Rotate))
} }
if o.Flip > 0 {
image, err = vipsFlip(image, o.Flip) if o.Flip {
direction = HORIZONTAL
} else if o.Flop {
direction = VERTICAL
}
if direction != -1 {
image, err = vipsFlip(image, direction)
} }
return image, err return image, err

Loading…
Cancel
Save