Beispiel #1
// Private: Create a blank magick wand with size width and height
// Params:
// - format: format of the new image
// - width: width of the new image
// - height: height of the new image
// Examples
//  blankWand("jpg", 100, 100)
// Return *C.MagickWand
func blankWand(format string, width, height int) *C.MagickWand {
	wand := C.NewMagickWand()
	cformat := C.CString(format)
	noneBackground := C.CString("none")

	C.MagickSetFormat(wand, C.CString(format))
	pixel := C.NewPixelWand()
	defer C.DestroyPixelWand(pixel)

	C.PixelSetColor(pixel, noneBackground)
	C.MagickSetSize(wand, C.size_t(width), C.size_t(height))
	C.MagickNewImage(wand, C.size_t(width), C.size_t(height), pixel)
	return wand
Beispiel #2
Sets the file or blob format (e.g. "BMP") to be used when a file or blob is read. Usually this is
not necessary because GraphicsMagick is able to auto-detect the format based on the file header
(or the file extension), but some formats do not use a unique header or the selection may be ambigious.
 Use MagickSetImageFormat() to set the format to be used when a file or blob is to be written.

format: The file or blob format
func (this *Image) SetFormat(format string) error {
	if this.magickWand == nil {
		return errors.New("error set image format:magickwand is nil")

	var cs *C.char = C.CString(format)
	status := C.MagickSetFormat(this.magickWand, cs)
	if status == 0 {
		var etype int
		descr := C.MagickGetException(this.magickWand, (*C.ExceptionType)(unsafe.Pointer(&etype)))
		defer C.MagickRelinquishMemory(unsafe.Pointer(descr))
		return errors.New(fmt.Sprintf("error set image format: %s (ExceptionType = %d)", C.GoString(descr), etype))

	return nil
Beispiel #3
// Sets the format of the magick wand.
func (mw *MagickWand) SetFormat(format string) error {
	csformat := C.CString(format)
	C.MagickSetFormat(, csformat)
	return mw.GetLastError()