mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-07 21:48:13 -08:00
feat(#20): support flop operation (interface broken, sorry im still beta)
This commit is contained in:
parent
2d17baca0d
commit
414fe40c91
5 changed files with 25 additions and 7 deletions
|
|
@ -43,6 +43,7 @@ The [install script](https://github.com/lovell/sharp/blob/master/preinstall.sh)
|
|||
- Crop
|
||||
- Rotate
|
||||
- Flip
|
||||
- Flop
|
||||
- Thumbnail
|
||||
- Extract area
|
||||
- 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)
|
||||
- [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
|
||||
```
|
||||
|
|
|
|||
4
image.go
4
image.go
|
|
@ -82,13 +82,13 @@ func (i *Image) Rotate(a Angle) ([]byte, error) {
|
|||
|
||||
// Flip the image about the vertical Y axis
|
||||
func (i *Image) Flip() ([]byte, error) {
|
||||
options := Options{Flip: VERTICAL}
|
||||
options := Options{Flip: true}
|
||||
return i.Process(options)
|
||||
}
|
||||
|
||||
// Flop the image about the horizontal X axis
|
||||
func (i *Image) Flop() ([]byte, error) {
|
||||
options := Options{Flip: VERTICAL}
|
||||
options := Options{Flop: true}
|
||||
return i.Process(options)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -112,6 +112,14 @@ func TestImageFlip(t *testing.T) {
|
|||
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) {
|
||||
buf, err := initImage("test_flip_out.jpg").Rotate(90)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -68,9 +68,10 @@ type Options struct {
|
|||
Crop bool
|
||||
Enlarge bool
|
||||
Embed bool
|
||||
Flip bool
|
||||
Flop bool
|
||||
Type ImageType
|
||||
Rotate Angle
|
||||
Flip Direction
|
||||
Gravity Gravity
|
||||
Interpolator Interpolator
|
||||
}
|
||||
|
|
|
|||
14
resize.go
14
resize.go
|
|
@ -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) {
|
||||
var err error
|
||||
var direction Direction = -1
|
||||
|
||||
rotation, flip := calculateRotationAndFlip(image, o.Rotate)
|
||||
if flip {
|
||||
o.Flip = HORIZONTAL
|
||||
o.Flip = flip
|
||||
}
|
||||
if rotation > D0 && o.Rotate == 0 {
|
||||
o.Rotate = rotation
|
||||
|
|
@ -172,8 +173,15 @@ func rotateImage(image *C.struct__VipsImage, o Options) (*C.struct__VipsImage, e
|
|||
if o.Rotate > 0 {
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue