Exemplo n.º 1
0
Arquivo: mage.go Projeto: dqminh/mage
// 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")
	defer C.free(unsafe.Pointer(cformat))
	defer C.free(unsafe.Pointer(noneBackground))

	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
}
Exemplo n.º 2
0
/*
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)
	defer C.free(unsafe.Pointer(cs))
	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
}
Exemplo n.º 3
0
// Sets the format of the magick wand.
func (mw *MagickWand) SetFormat(format string) error {
	csformat := C.CString(format)
	defer C.free(unsafe.Pointer(csformat))
	C.MagickSetFormat(mw.mw, csformat)
	return mw.GetLastError()
}