Beispiel #1
0
func (img *Image) GetBytes() []byte {
	size := 0
	buf := C.MagickGetImageBlob(img.wand, (*C.size_t)(unsafe.Pointer(&size)))
	defer C.MagickRelinquishMemory(unsafe.Pointer(buf))

	return C.GoBytes(unsafe.Pointer(buf), C.int(size))
}
Beispiel #2
0
/* Implements direct to memory image formats. */
func (w *MagickWand) ImageBlob(length *uint) []byte {
	blobPtr := unsafe.Pointer(C.MagickGetImageBlob(w.wand, (*C.size_t)(unsafe.Pointer(length))))
	blob := C.GoBytes(blobPtr, C.int(int(*length)))
	// need free blob memory
	C.MagickRelinquishMemory(blobPtr)
	return blob
}
Beispiel #3
0
// Writes canvas to a file, returns true on success.
func (cv Canvas) GetImageBlob() []byte {
	cv.Update()
	var length C.size_t
	data := C.MagickGetImageBlob(cv.wand, &length)
	bin := C.GoBytes(unsafe.Pointer(data), C.int(length))
	C.MagickRelinquishMemory(unsafe.Pointer(data))
	return bin
}
Beispiel #4
0
// Public: export the current image into a blob. Also destroy the current wand
//
// Examples:
//  im = NewMage()
//  original, err := ioutil.ReadFile("test.jpg")
//  success := im.ReadBlob(original)
//  imageBytes := im.ExportBlob()
func (m *Mage) ExportBlob() []byte {
	defer m.Destroy()
	newSize := C.size_t(0)
	C.MagickResetIterator(m.wand)
	image := C.MagickGetImageBlob(m.wand, &newSize)
	imagePointer := unsafe.Pointer(image)
	defer C.MagickRelinquishMemory(imagePointer)
	return C.GoBytes(imagePointer, C.int(newSize))
}
Beispiel #5
0
// Get image data as a byte array.
func (self *Canvas) GetImageBlob() ([]byte, error) {
	var size C.size_t = 0

	p := unsafe.Pointer(C.MagickGetImageBlob(self.wand, &size))
	if size == 0 {
		return nil, errors.New("Could not get image blob.")
	}

	blob := C.GoBytes(p, C.int(size))

	C.MagickRelinquishMemory(p)

	return blob, nil
}
Beispiel #6
0
//get image as byte array
func (self *Canvas) GetImageBlob() ([]byte, error) {
	var imageSize C.size_t = 0

	imageBlobPointer := unsafe.Pointer(C.MagickGetImageBlob(self.wand, &imageSize))
	if imageSize == 0 {
		return nil, fmt.Errorf("Could not get image blob \n")
	}

	goBlob := C.GoBytes(imageBlobPointer, C.int(imageSize))

	C.MagickRelinquishMemory(imageBlobPointer)

	return goBlob, nil
}
Beispiel #7
0
// Implements direct to memory image formats. It returns the image as a blob
func (self Canvas) Blob(length *uint) []byte {
	ptr := unsafe.Pointer(C.MagickGetImageBlob(self.wand, (*C.size_t)(unsafe.Pointer(length))))
	data := C.GoBytes(ptr, C.int(*length))
	C.MagickRelinquishMemory(ptr)
	return data
}