代码拉取完成,页面将自动刷新
package caire
import (
"image"
"testing"
"github.com/stretchr/testify/assert"
)
func TestResize_ShrinkImageWidth(t *testing.T) {
assert := assert.New(t)
img := image.NewNRGBA(image.Rect(0, 0, imgWidth, imgHeight))
var c = NewCarver(img.Bounds().Dx(), img.Bounds().Dy())
newWidth := imgWidth / 2
p.NewWidth = newWidth
p.NewHeight = imgHeight
for x := 0; x < newWidth; x++ {
width, height := img.Bounds().Max.X, img.Bounds().Max.Y
c = NewCarver(width, height)
c.ComputeSeams(p, img)
seams := c.FindLowestEnergySeams(p)
img = c.RemoveSeam(img, seams, p.Debug)
}
imgWidth := img.Bounds().Max.X
assert.Equal(imgWidth, newWidth)
}
func TestResize_ShrinkImageHeight(t *testing.T) {
assert := assert.New(t)
img := image.NewNRGBA(image.Rect(0, 0, imgWidth, imgHeight))
var c = NewCarver(img.Bounds().Dx(), img.Bounds().Dy())
newHeight := imgHeight / 2
p.NewWidth = imgWidth
p.NewHeight = newHeight
img = c.RotateImage90(img)
for x := 0; x < newHeight; x++ {
width, height := img.Bounds().Max.X, img.Bounds().Max.Y
c = NewCarver(width, height)
c.ComputeSeams(p, img)
seams := c.FindLowestEnergySeams(p)
img = c.RemoveSeam(img, seams, p.Debug)
}
img = c.RotateImage270(img)
imgHeight := img.Bounds().Max.Y
assert.Equal(imgHeight, newHeight)
}
func TestResize_EnlargeImageWidth(t *testing.T) {
assert := assert.New(t)
img := image.NewNRGBA(image.Rect(0, 0, imgWidth, imgHeight))
var c = NewCarver(img.Bounds().Dx(), img.Bounds().Dy())
newWidth := imgWidth * 2
p.NewWidth = newWidth
p.NewHeight = imgHeight
for x := 0; x < newWidth; x++ {
width, height := img.Bounds().Max.X, img.Bounds().Max.Y
c = NewCarver(width, height)
c.ComputeSeams(p, img)
seams := c.FindLowestEnergySeams(p)
img = c.AddSeam(img, seams, p.Debug)
}
imgWidth := img.Bounds().Max.X - img.Bounds().Dx()
assert.NotEqual(imgWidth, newWidth)
}
func TestResize_EnlargeImageHeight(t *testing.T) {
assert := assert.New(t)
img := image.NewNRGBA(image.Rect(0, 0, imgWidth, imgHeight))
var c = NewCarver(img.Bounds().Dx(), img.Bounds().Dy())
newHeight := imgHeight * 2
p.NewWidth = imgWidth
p.NewHeight = newHeight
img = c.RotateImage90(img)
for x := 0; x < newHeight; x++ {
width, height := img.Bounds().Max.X, img.Bounds().Max.Y
c = NewCarver(width, height)
c.ComputeSeams(p, img)
seams := c.FindLowestEnergySeams(p)
img = c.AddSeam(img, seams, p.Debug)
}
img = c.RotateImage270(img)
imgHeight := img.Bounds().Max.Y - img.Bounds().Dy()
assert.NotEqual(imgHeight, newHeight)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。