Exemplo n.º 1
0
/*
WriteImageBlob() writes this image wand to Blob
*/
func (this *Image) WriteImageBlob() error {
	var err error = nil
	tran := this.Cat.NewTransaction("GraphicsMagickCmd", "WriteImageBlob")
	defer func() {
		tran.SetStatus(err)
		tran.Complete()
	}()
	if this.magickWand == nil {
		err = errors.New("error write image to blob:magickwand is nil")
		return err
	}
	var sizep int = 0

	blob := C.MagickWriteImageBlob(this.magickWand, (*C.size_t)(unsafe.Pointer(&sizep)))
	if blob != nil {
		defer C.free(unsafe.Pointer(blob))
	} else {
		var etype int
		descr := C.MagickGetException(this.magickWand, (*C.ExceptionType)(unsafe.Pointer(&etype)))
		defer C.MagickRelinquishMemory(unsafe.Pointer(descr))
		err = errors.New(fmt.Sprintf("error write image to blob: %s (ExceptionType=%d)", C.GoString(descr), etype))
		return err
	}

	this.Blob = C.GoBytes(unsafe.Pointer(blob), C.int(sizep))

	return nil
}
Exemplo n.º 2
0
/*
WriteImageBlob() writes this image wand to Blob
*/
func (this *Image) WriteImageBlob() error {
	if this.magickWand == nil {
		return errors.New("error write image to blob:magickwand is nil")
	}
	var sizep int = 0

	blob := C.MagickWriteImageBlob(this.magickWand, (*C.size_t)(unsafe.Pointer(&sizep)))
	if blob != nil {
		defer C.free(unsafe.Pointer(blob))
	} else {
		var etype int
		descr := C.MagickGetException(this.magickWand, (*C.ExceptionType)(unsafe.Pointer(&etype)))
		defer C.MagickRelinquishMemory(unsafe.Pointer(descr))
		err := errors.New(fmt.Sprintf("error write image to blob: %s (ExceptionType=%d)", C.GoString(descr), etype))
		return err
	}

	this.Blob = C.GoBytes(unsafe.Pointer(blob), C.int(sizep))

	return nil
}