Esempio n. 1
0
func setKeywords(img *model.Image, path string, kwds []string) error {
	// charset issues?
	// log.Printf("%s: kwds: %d\n", path, len(kwds))
	tmp := "/tmp/k.txt"
	text := "2#25#Keyword=" + strings.Join(kwds, ";")
	err := ioutil.WriteFile(tmp, []byte(text), 0777)
	if err != nil {
		return err
	}
	cmd := exec.Command(
		*model.BinRoot+"mogrify", "-comment", "JFIFComment", "-profile",
		"8BIMTEXT:"+tmp, path)
	out, err := cmd.Output()
	if err != nil {
		log.Printf("%v: %s\n", cmd.Args, out)
		return err
	}
	os.Chtimes(path, img.FileTime(), img.FileTime())
	return nil
}
Esempio n. 2
0
func keywordsToSet(img *model.Image, file_kwds []string,
	oldex map[string][]string) ([]string, bool) {
	// log.Printf("%s file: %s\n", img.Name(), strings.Join(file_kwds, ", "))
	// log.Printf("%s db  : %s\n", img.Name(), strings.Join(img.Keywords(), ", "))
	present := make(map[string]bool)
	var kwds []string
	var k string
	for _, k = range img.Keywords() {
		kwds = appendIfNew(kwds, k, present)
	}
	for _, k = range file_kwds {
		kwds = appendIfNew(kwds, k, present)
	}
	old_kwds, has_old := oldex[img.Name()]
	if has_old {
		for _, k = range old_kwds {
			kwds = appendIfNew(kwds, k, present)
		}
	}
	return kwds, len(kwds) != len(file_kwds)
}