Exemple #1
0
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)))
}
Exemple #2
0
// 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
}
Exemple #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
}
Exemple #4
0
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
}
Exemple #5
0
// 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
}