mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-07 21:48:13 -08:00
fix(#28): zoom requires extract params
This commit is contained in:
parent
3f063b6a2f
commit
924be1d3f4
3 changed files with 24 additions and 15 deletions
|
|
@ -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)
|
||||
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.
|
||||
|
||||
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).
|
||||
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).
|
||||
|
||||
**Note**: bimg is still beta. Do not use in production yet
|
||||
|
||||
|
|
@ -653,3 +652,5 @@ type Watermark struct {
|
|||
## License
|
||||
|
||||
MIT - Tomas Aparicio
|
||||
|
||||
[](https://sourcegraph.com/github.com/h2non/bimg)
|
||||
|
|
|
|||
7
image.go
7
image.go
|
|
@ -81,9 +81,10 @@ func (i *Image) Watermark(w Watermark) ([]byte, error) {
|
|||
return i.Process(options)
|
||||
}
|
||||
|
||||
// Zoom the image by the given factor
|
||||
func (i *Image) Zoom(level int) ([]byte, error) {
|
||||
options := Options{Zoom: level}
|
||||
// Zoom the image by the given factor.
|
||||
// You should probably call Extract() before
|
||||
func (i *Image) Zoom(factor int) ([]byte, error) {
|
||||
options := Options{Zoom: factor}
|
||||
return i.Process(options)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ func TestImageResize(t *testing.T) {
|
|||
func TestImageExtract(t *testing.T) {
|
||||
buf, err := initImage("test.jpg").Extract(100, 100, 300, 300)
|
||||
if err != nil {
|
||||
t.Errorf("Cannot process the image: %#v", err)
|
||||
t.Errorf("Cannot process the image: %s", err)
|
||||
}
|
||||
|
||||
err = assertSize(buf, 300, 300)
|
||||
|
|
@ -51,7 +51,7 @@ func TestImageEnlarge(t *testing.T) {
|
|||
func TestImageCrop(t *testing.T) {
|
||||
buf, err := initImage("test.jpg").Crop(800, 600, NORTH)
|
||||
if err != nil {
|
||||
t.Errorf("Cannot process the image: %#v", err)
|
||||
t.Errorf("Cannot process the image: %s", err)
|
||||
}
|
||||
|
||||
err = assertSize(buf, 800, 600)
|
||||
|
|
@ -65,7 +65,7 @@ func TestImageCrop(t *testing.T) {
|
|||
func TestImageCropByWidth(t *testing.T) {
|
||||
buf, err := initImage("test.jpg").CropByWidth(600)
|
||||
if err != nil {
|
||||
t.Errorf("Cannot process the image: %#v", err)
|
||||
t.Errorf("Cannot process the image: %s", err)
|
||||
}
|
||||
|
||||
err = assertSize(buf, 600, 375)
|
||||
|
|
@ -79,7 +79,7 @@ func TestImageCropByWidth(t *testing.T) {
|
|||
func TestImageCropByHeight(t *testing.T) {
|
||||
buf, err := initImage("test.jpg").CropByHeight(300)
|
||||
if err != nil {
|
||||
t.Errorf("Cannot process the image: %#v", err)
|
||||
t.Errorf("Cannot process the image: %s", err)
|
||||
}
|
||||
|
||||
err = assertSize(buf, 480, 300)
|
||||
|
|
@ -93,7 +93,7 @@ func TestImageCropByHeight(t *testing.T) {
|
|||
func TestImageThumbnail(t *testing.T) {
|
||||
buf, err := initImage("test.jpg").Thumbnail(100)
|
||||
if err != nil {
|
||||
t.Errorf("Cannot process the image: %#v", err)
|
||||
t.Errorf("Cannot process the image: %s", err)
|
||||
}
|
||||
|
||||
err = assertSize(buf, 100, 100)
|
||||
|
|
@ -138,7 +138,7 @@ func TestImageWatermarkNoReplicate(t *testing.T) {
|
|||
image := initImage("test.jpg")
|
||||
_, err := image.Crop(800, 600, NORTH)
|
||||
if err != nil {
|
||||
t.Errorf("Cannot process the image: %#v", err)
|
||||
t.Errorf("Cannot process the image: %s", err)
|
||||
}
|
||||
|
||||
buf, err := image.Watermark(Watermark{
|
||||
|
|
@ -166,12 +166,19 @@ func TestImageWatermarkNoReplicate(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 {
|
||||
t.Errorf("Cannot process the image: %#v", err)
|
||||
t.Errorf("Cannot extract the image: %s", err)
|
||||
}
|
||||
|
||||
err = assertSize(buf, 3360, 2100)
|
||||
buf, err := image.Zoom(1)
|
||||
if err != nil {
|
||||
t.Errorf("Cannot process the image: %s", err)
|
||||
}
|
||||
|
||||
err = assertSize(buf, 800, 600)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue