Beispiel #1
0
// ToBlob takes a (transformed) MagickImage and returns a byte slice in the format you specify with extension.
// Magick uses the extension to transform the image in to the proper encoding (e.g. "jpg", "png")
func (im *MagickImage) ToBlob(extension string) (blob []byte, err error) {
	exception := C.AcquireExceptionInfo()
	defer C.DestroyExceptionInfo(exception)
	c_outpath := C.CString("image." + extension)
	defer C.free(unsafe.Pointer(c_outpath))
	C.SetImageInfoFilename(im.ImageInfo, c_outpath)
	var outlength (C.size_t)
	outblob := C.ImageToBlob(im.ImageInfo, im.Image, &outlength, exception)
	if failed := C.CheckException(exception); failed == C.MagickTrue {
		return nil, ErrorFromExceptionInfo(exception)
	}
	char_pointer := unsafe.Pointer(outblob)
	defer C.free(char_pointer)
	return C.GoBytes(char_pointer, (C.int)(outlength)), nil
}
Beispiel #2
0
func imageToBlob(info *Info, im *Image, s *C.size_t, ex *C.ExceptionInfo) unsafe.Pointer {
	return C.ImageToBlob(info.info, im.image, s, ex)
}