Example #1
0
func (ac *ActionsConfig) Pixelette(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {

	username := ps.ByName("username")
	chopid := ps.ByName("chopid")
	s := chopper.NewSlapchop(ac.Host, username, chopid)
	t_files, _ := s.LoadFiles(ac.UploadDir)

	up := s.UploadPoint(ac.UploadDir)
	var sR, sG, sB, sA uint64
	sR, sG, sB, sA = 0, 0, 0, 0
	for _, f := range t_files {
		file, _ := os.Open(fmt.Sprintf("%s/%s", up, f.Name()))
		img, _, _ := chopper.Load(file)
		subImg := image.NewRGBA(image.Rect(0, 0, ac.TileSize, ac.TileSize))
		draw.Draw(subImg, subImg.Bounds(), *img, image.Rect(0, 0, ac.TileSize, ac.TileSize).Min, draw.Src)

		for x := 0; x <= ac.TileSize; x++ {
			for y := 0; y <= ac.TileSize; y++ {
				r, g, b, a := subImg.At(x, y).RGBA()
				sR += uint64(r)
				sG += uint64(g)
				sB += uint64(b)
				sA += uint64(a)
			}
		}
		ms := uint64(ac.TileSize * ac.TileSize)
		println(sR/ms, sG/ms, sB/ms, sA/ms)

	}

	w.WriteHeader(http.StatusOK)
	w.Write([]byte(``))
}
Example #2
0
func (ac *ActionsConfig) Preview(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {

	username := ps.ByName("username")
	chopid := ps.ByName("chopid")
	s := chopper.NewSlapchop(ac.Host, username, chopid)
	t_files, _ := s.LoadFiles(ac.UploadDir)
	tiles := s.LoadTiles(ac.HostName, t_files)
	grid := s.Grid(tiles)

	html := mustache.RenderFile(ac.TemplatePath, grid)

	w.WriteHeader(http.StatusOK)
	w.Write([]byte(html))
}
Example #3
0
func (ac *ActionsConfig) ReadAll(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {

	username := ps.ByName("username")
	path := fmt.Sprintf("%s/%s", ac.UploadDir, username)
	dirs, _ := ioutil.ReadDir(path)
	slapchops := make([]*chopper.SlapchopEntry, len(dirs))
	for i, d := range dirs {
		slapchops[i] = chopper.NewSlapchop(ac.Host, username, d.Name())
	}
	resp := chopper.ReadAllResponse{
		User:      username,
		Slapchops: slapchops,
	}

	w.WriteHeader(http.StatusOK)
	json_resp, _ := json.Marshal(&resp)
	w.Write(json_resp)
}
Example #4
0
func (ac *ActionsConfig) Read(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {

	username := ps.ByName("username")
	chopid := ps.ByName("chopid")
	s := chopper.NewSlapchop(ac.Host, username, chopid)
	t_files, _ := s.LoadFiles(ac.UploadDir)
	tiles := s.LoadTiles(ac.HostName, t_files)

	resp := chopper.ReadResponse{
		User:  username,
		Id:    chopid,
		Tiles: tiles,
	}

	w.WriteHeader(http.StatusOK)
	json_resp, _ := json.Marshal(&resp)
	w.Write(json_resp)
}