예제 #1
0
func checkBoundsAndPix(b1, b2 image.Rectangle, pix1, pix2 []uint8) bool {
	if !b1.Eq(b2) {
		return false
	}
	if len(pix1) != len(pix2) {
		return false
	}
	for i := 0; i < len(pix1); i++ {
		if pix1[i] != pix2[i] {
			return false
		}
	}
	return true
}
예제 #2
0
func thumbnailRez(imgSrc image.Image, size image.Point, trimmedBounds image.Rectangle) image.Image {

	img := ConvertToRGBAIfNecessary(imgSrc)
	if !trimmedBounds.Empty() && !trimmedBounds.Eq(img.Bounds()) {
		img = img.SubImage(trimmedBounds).(*image.RGBA)
	}

	b := img.Bounds()
	imgSize := image.Point{b.Dx(), b.Dy()}
	thumbSize, downscaling := SizePreservingAspect(imgSize, size)

	resizedImg := img
	if downscaling {
		resizedImg = CreateRGBAImageOfSize(thumbSize)
		convert(resizedImg, img, false, rez.NewBicubicFilter())
	}

	dstImg := CreateRGBAImageOfSize(size)
	// paint the background
	//draw.Draw(dstImg, dstImg.Bounds(), &image.Uniform{bgColor}, image.ZP, draw.Src)
	drawCentered(dstImg, resizedImg)
	return dstImg
}
예제 #3
0
func thumbnailNfnt(imgSrc image.Image, size image.Point, trimmedBounds image.Rectangle) image.Image {

	img := ConvertToRGBAIfNecessary(imgSrc)
	if !trimmedBounds.Empty() && !trimmedBounds.Eq(img.Bounds()) {
		img = img.SubImage(trimmedBounds).(*image.RGBA)
	}

	b := img.Bounds()
	imgSize := image.Point{b.Dx(), b.Dy()}
	thumbSize, downscaling := SizePreservingAspect(imgSize, size)

	var resizedImg image.Image = img
	if downscaling {
		// resize.Resize returns *image.RGBA64
		resizedImg = resize.Resize(uint(thumbSize.X), uint(thumbSize.Y), img, resize.Bilinear)
	}

	dstImg := CreateRGBAImageOfSize(size)
	// paint the background
	//draw.Draw(dstImg, dstImg.Bounds(), &image.Uniform{bgColor}, image.ZP, draw.Src)
	drawCentered(dstImg, resizedImg)
	return dstImg
}