mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-07 21:48:13 -08:00
refactor: crop and tests
This commit is contained in:
parent
b20ddbb8f3
commit
2e90c11e5b
3 changed files with 45 additions and 8 deletions
14
README.md
14
README.md
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
Go library for blazing fast image processing based on [libvips](https://github.com/jcupitt/libvips) using C bindings.
|
||||
|
||||
**bimg** was focused on performance, resizing an image with libvips is typically 4x faster than using the quickest ImageMagick and GraphicsMagick settings.
|
||||
libvips is typically 4x faster than using the quickest ImageMagick and GraphicsMagick settings, and even 8x faster with JPEG format. It support JPEG, PNG, WEBP, TIFF and Magick image formats.
|
||||
|
||||
**bimg** was heavily inspired in [sharp](https://github.com/lovell/sharp), a great node.js package for image processing build by [Lovell Fuller](https://github.com/lovell).
|
||||
bimg was heavily inspired in [sharp](https://github.com/lovell/sharp), a great node.js package for image processing build by [Lovell Fuller](https://github.com/lovell).
|
||||
|
||||
`Work in progress`
|
||||
|
||||
|
|
@ -29,6 +29,16 @@ curl -s https://raw.githubusercontent.com/lovell/sharp/master/preinstall.sh | su
|
|||
|
||||
The [install script](https://github.com/lovell/sharp/blob/master/preinstall.sh) requires `curl` and `pkg-config`.
|
||||
|
||||
## Image operations
|
||||
|
||||
- Resize
|
||||
- Crop
|
||||
- Enlarge
|
||||
- Zoom
|
||||
- Extract
|
||||
- Image metadata
|
||||
- Image conversion to multiple formats
|
||||
|
||||
## API
|
||||
|
||||
```go
|
||||
|
|
|
|||
9
image.go
9
image.go
|
|
@ -22,6 +22,15 @@ func (i *Image) Extract(top int, left int, width int, height int) ([]byte, error
|
|||
return i.Process(options)
|
||||
}
|
||||
|
||||
func (i *Image) Crop(width int, height int) ([]byte, error) {
|
||||
options := Options{
|
||||
Width: width,
|
||||
Height: height,
|
||||
Crop: true,
|
||||
}
|
||||
return i.Process(options)
|
||||
}
|
||||
|
||||
func (i *Image) Rotate(a Angle) ([]byte, error) {
|
||||
options := Options{Rotate: a}
|
||||
return i.Process(options)
|
||||
|
|
|
|||
|
|
@ -7,13 +7,31 @@ import (
|
|||
)
|
||||
|
||||
func TestImageResize(t *testing.T) {
|
||||
data, _ := os.Open("fixtures/test.jpg")
|
||||
buf, err := ioutil.ReadAll(data)
|
||||
|
||||
image := NewImage(buf)
|
||||
|
||||
buf, err = image.Resize(300, 240)
|
||||
image := readImage()
|
||||
_, err := image.Resize(300, 240)
|
||||
if err != nil {
|
||||
t.Errorf("Cannot process the image: %#v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestImageCrop(t *testing.T) {
|
||||
image := readImage()
|
||||
_, err := image.Crop(300, 240)
|
||||
if err != nil {
|
||||
t.Errorf("Cannot process the image: %#v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestImageRotate(t *testing.T) {
|
||||
image := readImage()
|
||||
_, err := image.Rotate(D90)
|
||||
if err != nil {
|
||||
t.Errorf("Cannot process the image: %#v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func readImage() *Image {
|
||||
data, _ := os.Open("fixtures/test.jpg")
|
||||
buf, _ := ioutil.ReadAll(data)
|
||||
return NewImage(buf)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue