fix(#28): zoom requires extract params

master
Tomas Aparicio 11 years ago
parent 3f063b6a2f
commit 924be1d3f4

@ -6,12 +6,11 @@ bimg is designed to be a small and efficient library with a generic and useful s
It uses internally libvips, which requires a [low memory footprint](http://www.vips.ecs.soton.ac.uk/index.php?title=Speed_and_Memory_Use) It uses internally libvips, which requires a [low memory footprint](http://www.vips.ecs.soton.ac.uk/index.php?title=Speed_and_Memory_Use)
and it's typically 4x faster than using the quickest ImageMagick and GraphicsMagick settings or Go native `image` package, and in some cases it's even 8x faster processing JPEG images. and it's typically 4x faster than using the quickest ImageMagick and GraphicsMagick settings or Go native `image` package, and in some cases it's even 8x faster processing JPEG images.
It can read JPEG, PNG, WEBP and TIFF formats and output to JPEG, PNG and WEBP, including conversion betweem them. It supports common [image operations](#supported-image-operations) such as crop, resize, rotate, zoom, watermark... It can read JPEG, PNG, WEBP and TIFF formats and output to JPEG, PNG and WEBP, including conversion between them. It supports common [image operations](#supported-image-operations) such as crop, resize, rotate, zoom, watermark...
For getting started, take a look to the [examples](#examples) and [programmatic API](https://godoc.org/github.com/h2non/bimg) documentation. For getting started, take a look to the [examples](#examples) and [programmatic API](https://godoc.org/github.com/h2non/bimg) documentation.
bimg was heavily inspired in [sharp](https://github.com/lovell/sharp), bimg was heavily inspired in [sharp](https://github.com/lovell/sharp), its homologous package built for node.js by [Lovell Fuller](https://github.com/lovell).
its homologous package built for node.js by [Lovell Fuller](https://github.com/lovell).
**Note**: bimg is still beta. Do not use in production yet **Note**: bimg is still beta. Do not use in production yet
@ -653,3 +652,5 @@ type Watermark struct {
## License ## License
MIT - Tomas Aparicio MIT - Tomas Aparicio
[![views](https://sourcegraph.com/api/repos/github.com/h2non/bimg/.counters/views.svg)](https://sourcegraph.com/github.com/h2non/bimg)

@ -81,9 +81,10 @@ func (i *Image) Watermark(w Watermark) ([]byte, error) {
return i.Process(options) return i.Process(options)
} }
// Zoom the image by the given factor // Zoom the image by the given factor.
func (i *Image) Zoom(level int) ([]byte, error) { // You should probably call Extract() before
options := Options{Zoom: level} func (i *Image) Zoom(factor int) ([]byte, error) {
options := Options{Zoom: factor}
return i.Process(options) return i.Process(options)
} }

@ -23,7 +23,7 @@ func TestImageResize(t *testing.T) {
func TestImageExtract(t *testing.T) { func TestImageExtract(t *testing.T) {
buf, err := initImage("test.jpg").Extract(100, 100, 300, 300) buf, err := initImage("test.jpg").Extract(100, 100, 300, 300)
if err != nil { if err != nil {
t.Errorf("Cannot process the image: %#v", err) t.Errorf("Cannot process the image: %s", err)
} }
err = assertSize(buf, 300, 300) err = assertSize(buf, 300, 300)
@ -51,7 +51,7 @@ func TestImageEnlarge(t *testing.T) {
func TestImageCrop(t *testing.T) { func TestImageCrop(t *testing.T) {
buf, err := initImage("test.jpg").Crop(800, 600, NORTH) buf, err := initImage("test.jpg").Crop(800, 600, NORTH)
if err != nil { if err != nil {
t.Errorf("Cannot process the image: %#v", err) t.Errorf("Cannot process the image: %s", err)
} }
err = assertSize(buf, 800, 600) err = assertSize(buf, 800, 600)
@ -65,7 +65,7 @@ func TestImageCrop(t *testing.T) {
func TestImageCropByWidth(t *testing.T) { func TestImageCropByWidth(t *testing.T) {
buf, err := initImage("test.jpg").CropByWidth(600) buf, err := initImage("test.jpg").CropByWidth(600)
if err != nil { if err != nil {
t.Errorf("Cannot process the image: %#v", err) t.Errorf("Cannot process the image: %s", err)
} }
err = assertSize(buf, 600, 375) err = assertSize(buf, 600, 375)
@ -79,7 +79,7 @@ func TestImageCropByWidth(t *testing.T) {
func TestImageCropByHeight(t *testing.T) { func TestImageCropByHeight(t *testing.T) {
buf, err := initImage("test.jpg").CropByHeight(300) buf, err := initImage("test.jpg").CropByHeight(300)
if err != nil { if err != nil {
t.Errorf("Cannot process the image: %#v", err) t.Errorf("Cannot process the image: %s", err)
} }
err = assertSize(buf, 480, 300) err = assertSize(buf, 480, 300)
@ -93,7 +93,7 @@ func TestImageCropByHeight(t *testing.T) {
func TestImageThumbnail(t *testing.T) { func TestImageThumbnail(t *testing.T) {
buf, err := initImage("test.jpg").Thumbnail(100) buf, err := initImage("test.jpg").Thumbnail(100)
if err != nil { if err != nil {
t.Errorf("Cannot process the image: %#v", err) t.Errorf("Cannot process the image: %s", err)
} }
err = assertSize(buf, 100, 100) err = assertSize(buf, 100, 100)
@ -138,7 +138,7 @@ func TestImageWatermarkNoReplicate(t *testing.T) {
image := initImage("test.jpg") image := initImage("test.jpg")
_, err := image.Crop(800, 600, NORTH) _, err := image.Crop(800, 600, NORTH)
if err != nil { if err != nil {
t.Errorf("Cannot process the image: %#v", err) t.Errorf("Cannot process the image: %s", err)
} }
buf, err := image.Watermark(Watermark{ buf, err := image.Watermark(Watermark{
@ -166,12 +166,19 @@ func TestImageWatermarkNoReplicate(t *testing.T) {
} }
func TestImageZoom(t *testing.T) { func TestImageZoom(t *testing.T) {
buf, err := initImage("test.jpg").Zoom(1) image := initImage("test.jpg")
_, err := image.Extract(100, 100, 400, 300)
if err != nil { if err != nil {
t.Errorf("Cannot process the image: %#v", err) t.Errorf("Cannot extract the image: %s", err)
}
buf, err := image.Zoom(1)
if err != nil {
t.Errorf("Cannot process the image: %s", err)
} }
err = assertSize(buf, 3360, 2100) err = assertSize(buf, 800, 600)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }

Loading…
Cancel
Save