Пример #1
0
// imgcmp compares the two images and returns an error if they differ.
func imgcmp(imgPath0, imgPath1 string) (err error) {
	img0, err := imgutil.ReadFile(imgPath0)
	if err != nil {
		return err
	}
	img1, err := imgutil.ReadFile(imgPath1)
	if err != nil {
		return err
	}
	err = cmp(img0, img1)
	if err != nil {
		return err
	}
	return nil
}
Пример #2
0
// loadResources loads the images required to render the grid and the markers.
func loadResources() (err error) {
	dataDir, err := goutil.SrcDir("github.com/mewmew/playground/archive/vaga/data")
	if err != nil {
		return err
	}
	imgGrid, err = imgutil.ReadFile(dataDir + "/grid.png")
	if err != nil {
		return err
	}
	imgO, err = imgutil.ReadFile(dataDir + "/o.png")
	if err != nil {
		return err
	}
	imgX, err = imgutil.ReadFile(dataDir + "/x.png")
	if err != nil {
		return err
	}
	return nil
}
Пример #3
0
// GetTileSprite returns a slise of type image.Image containing all tiles from
// all sprites from all layers including the nil tile with GID 0.
func (m *Map) GetTileSprite() (tileSprite []image.Image) {
	tileSprite = make([]image.Image, m.countSpriteTiles())
	k := 1
	for _, tileSet := range m.Tilesets {
		sprite, err := imgutil.ReadFile(tileSet.Image.Source)
		if err != nil {
			log.Fatalln(err)
		}
		spriteImg, ok := sprite.(SubImager)
		if ok != true {
			log.Fatalln("SubImage function not implemented for this image type")
		}
		for y := 0; y < tileSet.Image.Height; y += tileSet.TileHeight {
			for x := 0; x < tileSet.Image.Width; x += tileSet.TileWidth {
				rect := image.Rect(x, y, x+tileSet.TileWidth, y+tileSet.TileHeight)
				tileSprite[k] = spriteImg.SubImage(rect)
				k++
			}
		}
	}
	return tileSprite
}
Пример #4
0
// mimicry creates a git repository which mimics an image using a contribution
// history of carefully crafted commit dates. It expects a 51x7 image with a
// transparent background.
func mimicry(imgPath string) (err error) {
	img, err := imgutil.ReadFile(imgPath)
	if err != nil {
		return err
	}

	// Verify image dimensions.
	bounds := img.Bounds()
	width, height := bounds.Dx(), bounds.Dy()
	if width != Width || height != Height {
		return fmt.Errorf("mimicry: invalid image dimensions; expected %dx%d, got %dx%d", Width, Height, width, height)
	}

	// Create an empty git repository.
	name := pathutil.FileName(imgPath)
	cmd := exec.Command("git", "init", name)
	cmd.Stderr = os.Stderr
	err = cmd.Run()
	if err != nil {
		return err
	}

	// Forge a commit history based on the image.
	grid := new(Grid)
	for x := bounds.Min.X; x < bounds.Max.X; x++ {
		for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
			c := img.At(x, y)
			if !isTrans(c) {
				// Create a commit with a date that represents the (x,y)-coordinate.
				date := coordDate(x, y)
				fmt.Println("date:", date)

				grid.Set(x, y)
				fmt.Println(grid)

				filePath := filepath.Join(name, "README")
				err = ioutil.WriteFile(filePath, grid.Bytes(), 0644)
				if err != nil {
					return err
				}

				cmd = exec.Command("git", "add", "README")
				cmd.Stderr = os.Stderr
				cmd.Dir = name
				err = cmd.Run()
				if err != nil {
					return err
				}

				message := fmt.Sprintf("readme: Add the cell at coordinate (%d, %d).", x, y)
				cmd = exec.Command("git", "commit", "-m", message, "--date", date.Format("2006-01-02 15:04:05"))
				cmd.Stderr = os.Stderr
				cmd.Dir = name
				err = cmd.Run()
				if err != nil {
					return err
				}

			}
		}
	}

	return nil
}