图片去除边框(黑边,白边)
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() }
=====================
追加:
=====================
不明白,代码加上fuzz的效果没出来,命令行可以进行,也是醉了。
convert ~/Downloads/video1.jpg -fuzz 10% -trim ./trim.jpg
参考:
http://www.imagemagick.org/Usage/crop/#trim
http://blog.csdn.net/newborn2012/article/details/24964577
有疑问加站长微信联系(非本文作者)