用过的baidu空间,太难用了,还是cnblogs好用
GZ.Jackey
学无止境,博采众长。

图片去除边框(黑边,白边)

 

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()
}

 =========================

追加:为图片添加中文字

 

===================

func AddTextImage(Args []string) {
    imagick.Initialize()
    defer imagick.Terminate()
    mw := imagick.NewMagickWand()
    mw.ReadImage(Args[1])
    defer mw.Destroy()

    dw := imagick.NewDrawingWand()
    defer dw.Destroy()

    pw := imagick.NewPixelWand()
    pw.SetColor("red")
    defer pw.Destroy()
  #这里需要是字体文件的绝对路径
    dw.SetFont("./simsun.ttc")
    dw.SetFontSize(20)
    dw.SetFillColor(pw)
    dw.SetTextEncoding("UTF-8")
    mw.AnnotateImage(dw, 20, 20, 0, "@ 你好 Hello...")
    mw.DrawImage(dw)

    mw.WriteImage("textlog.jpg")
}

 

=====================

追加:

=====================

不明白,代码加上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

posted on 2015-02-10 11:29  GZ.Jackey  阅读(2668)  评论(0编辑  收藏  举报