Exemple #1
0
func Read(path string) (*C.Image, error) {
	strCopy(&imageInfo.filename, []byte(path))

	img := C.ReadImage(imageInfo, &exceptionInfo)
	if img == nil {
		C.CatchException(&exceptionInfo)
		return nil, fmt.Errorf(C.GoString(exceptionInfo.reason))
	}

	return img, nil
}
Exemple #2
0
// NewFromFile loads a file at filename into a MagickImage.
// Exceptions are returned as MagickErrors.
func NewFromFile(filename string) (im *MagickImage, err error) {
	exception := C.AcquireExceptionInfo()
	defer C.DestroyExceptionInfo(exception)
	info := C.AcquireImageInfo()
	c_filename := C.CString(filename)
	defer C.free(unsafe.Pointer(c_filename))
	C.SetImageInfoFilename(info, c_filename)
	image := C.ReadImage(info, exception)
	if failed := C.CheckException(exception); failed == C.MagickTrue {
		C.DestroyImageInfo(info)
		return nil, ErrorFromExceptionInfo(exception)
	}
	return &MagickImage{Image: image, ImageInfo: info}, nil
}