标签:
图片去除边框(黑边,白边)
package main import ( "fmt" "github.com/gographics/imagick/imagick" "io/ioutil" "os" "strconv" ) func ReadFile(path string) (string, error) { fi, err := os.Open(path) if err == nil { defer fi.Close() fd, err := ioutil.ReadAll(fi) return string(fd), err } else { return "", err } } func main() { arg_num := len(os.Args) if arg_num < 3 { fmt.Println("./tester [imagepath][trimdistance]") return } imagick.Initialize() defer imagick.Terminate() compMW := imagick.NewMagickWand() compMW.ReadImage(os.Args[1]) trimDistance, _ := strconv.ParseFloat(os.Args[2], 0) err := compMW.TrimImage(trimDistance) if err != nil { fmt.Println("trim failed, ", err) } else { compMW.TrimImage(trimDistance) compMW.WriteImage("./trim.jpg") fmt.Println("trim success") } compMW.Destroy() }
标签:
原文地址:http://www.cnblogs.com/zhangqingping/p/4283375.html