fix(#106): allow custom area extraction without x/y axis

master
Tomas Aparicio 9 years ago
parent 522cf71c73
commit 3c158381b0

@ -242,7 +242,7 @@ func extractOrEmbedImage(image *C.VipsImage, o Options) (*C.VipsImage, error) {
left, top := (o.Width-inWidth)/2, (o.Height-inHeight)/2 left, top := (o.Width-inWidth)/2, (o.Height-inHeight)/2
image, err = vipsEmbed(image, left, top, o.Width, o.Height, o.Extend, o.Background) image, err = vipsEmbed(image, left, top, o.Width, o.Height, o.Extend, o.Background)
break break
case o.Top != 0 || o.Left != 0: case o.Top > 0 || o.Left > 0 || o.AreaWidth > 0 || o.AreaHeight > 0:
if o.AreaWidth == 0 { if o.AreaWidth == 0 {
o.AreaHeight = o.Width o.AreaHeight = o.Width
} }

@ -284,6 +284,40 @@ func TestSharpen(t *testing.T) {
Write("fixtures/test_sharpen.jpg", newImg) Write("fixtures/test_sharpen.jpg", newImg)
} }
func TestExtractWithDefaultAxis(t *testing.T) {
options := Options{AreaWidth: 200, AreaHeight: 200}
buf, _ := Read("fixtures/test.jpg")
newImg, err := Resize(buf, options)
if err != nil {
t.Errorf("Resize(imgData, %#v) error: %#v", options, err)
}
size, _ := Size(newImg)
if size.Height != options.AreaHeight || size.Width != options.AreaWidth {
t.Fatalf("Invalid image size: %dx%d", size.Width, size.Height)
}
Write("fixtures/test_extract_defaults.jpg", newImg)
}
func TestExtractCustomAxis(t *testing.T) {
options := Options{Top: 100, Left: 100, AreaWidth: 200, AreaHeight: 200}
buf, _ := Read("fixtures/test.jpg")
newImg, err := Resize(buf, options)
if err != nil {
t.Errorf("Resize(imgData, %#v) error: %#v", options, err)
}
size, _ := Size(newImg)
if size.Height != options.AreaHeight || size.Width != options.AreaWidth {
t.Fatalf("Invalid image size: %dx%d", size.Width, size.Height)
}
Write("fixtures/test_extract_custom_axis.jpg", newImg)
}
func TestConvert(t *testing.T) { func TestConvert(t *testing.T) {
width, height := 300, 240 width, height := 300, 240
formats := [3]ImageType{PNG, WEBP, JPEG} formats := [3]ImageType{PNG, WEBP, JPEG}

Loading…
Cancel
Save