示例#1
0
文件: conv.go 项目: Joinhack/avconv
func Resize(fpath, tpath string, typ, cols, rows int) error {
	var mw *C.MagickWand = C.NewMagickWand()
	var cfpath = C.CString(fpath)
	var ctpath = C.CString(tpath)
	var etype C.ExceptionType
	defer func() {
		C.free(unsafe.Pointer(cfpath))
		C.free(unsafe.Pointer(ctpath))
	}()
	defer func() {
		C.ClearMagickWand(mw)
		C.DestroyMagickWand(mw)
	}()
	if C.MagickReadImage(mw, cfpath) == C.MagickFalse {
		goto ERR
	}

	if C.scale(mw, C.int(typ), C.int(cols), C.int(rows)) == C.MagickFalse {
		goto ERR
	}
	if C.MagickWriteImages(mw, ctpath, C.MagickTrue) == C.MagickFalse {
		goto ERR
	}
	return nil
ERR:
	etype = C.MagickGetExceptionType(mw)
	return errors.New(C.GoString(C.MagickGetException(mw, &etype)))
}
示例#2
0
文件: canvas.go 项目: d1on/gocanvas
// Opens an image file, returns true on success.
func (cv Canvas) Open(filename string) bool {
	status := C.MagickReadImage(cv.wand, C.CString(filename))
	if status == C.MagickFalse {
		return false
	}
	return true
}
示例#3
0
/* Reads an image or image sequence. */
func (w *MagickWand) ReadImage(fileName string) error {
	if C.MagickReadImage(w.wand, C.CString(fileName)) == C.MagickFalse {
		eStr, eCode := w.Exception()
		return fmt.Errorf("ReadImage() failed : [%d] %s", eStr, eCode)
	}

	return nil
}
示例#4
0
文件: canvas.go 项目: phacops/canvas
func (self *Canvas) SetCaption(content string) error {
	ccontent := C.CString("caption:" + content)
	defer C.free(unsafe.Pointer(ccontent))

	if C.MagickReadImage(self.wand, ccontent) == C.MagickFalse {
		return fmt.Errorf(`Could not open image "%s": %s`, content, self.Error())
	}

	return nil
}
示例#5
0
文件: canvas.go 项目: jmrobles/canvas
// Opens an image file, returns nil on success, error otherwise.
func (self Canvas) Open(filename string) error {
	stat, err := os.Stat(filename)
	if err != nil {
		return err
	}
	if stat.IsDir() == true {
		return fmt.Errorf(`Could not open file "%s": it's a directory!`, filename)
	}
	status := C.MagickReadImage(self.wand, C.CString(filename))
	if status == C.MagickFalse {
		return fmt.Errorf(`Could not open image "%s": %s`, filename, self.Error())
	}
	self.filename = filename
	return nil
}