Exemple #1
0
func (p *Page) concatImages() error {
	width := 0
	height := 0
	for _, i := range p.divImages {
		img, err := utility.DecodeImage(i)
		if err != nil {
			return err
		}
		height += img.Bounds().Size().Y
		if width < img.Bounds().Size().X {
			width = img.Bounds().Size().X
		}
	}
	dstRect := image.Rect(0, 0, width, height)
	dstImage := image.NewRGBA(dstRect)
	top := 0
	for _, i := range p.divImages {
		img, err := utility.DecodeImage(i)
		if err != nil {
			return err
		}
		srcPoint := image.Point{0, 0}
		dstRect := image.Rect(0, top, img.Bounds().Size().X, top+img.Bounds().Size().Y)
		draw.Draw(dstImage, dstRect, img, srcPoint, draw.Src)
		top += img.Bounds().Size().Y
	}
	return utility.SaveImage(dstImage, p.imagePath())
}
Exemple #2
0
func collectPages(urlIndexes []*UrlIndex) (pages []*Page, err error) {
	pageIndex := 0
	var tmpImages []string
	for _, u := range urlIndexes {
		for _, imgPath := range u.images() {
			//fmt.Printf("imgPath = %s\n", imgPath)
			img, err := utility.DecodeImage(imgPath)
			if err != nil {
				return nil, err
			}
			height := img.Bounds().Size().Y
			if math.Abs(float64(1600-height)) > 100 {
				tmpImages = append(tmpImages, imgPath)
				if len(tmpImages) == 2 {
					pages = append(pages, &Page{pageIndex, tmpImages})
					pageIndex++
				}
			} else {
				pages = append(pages, &Page{pageIndex, []string{imgPath}})
				pageIndex++
				tmpImages = []string{}
			}
		}
	}
	return pages, nil
}