Beispiel #1
0
// Returns a new canvas object.
func New() *Canvas {
	cv := &Canvas{}

	cv.Init()

	cv.wand = C.NewMagickWand()

	cv.fg = C.NewPixelWand()
	cv.bg = C.NewPixelWand()

	cv.fill = C.NewPixelWand()
	cv.stroke = C.NewPixelWand()

	cv.drawing = C.NewDrawingWand()

	//cv.SetColor("#ffffff")
	cv.SetBackgroundColor("none")

	cv.SetStrokeColor("#ffffff")
	cv.SetStrokeAntialias(true)
	cv.SetStrokeWidth(1.0)
	cv.SetStrokeOpacity(1.0)
	cv.SetStrokeLineCap(STROKE_ROUND_CAP)
	cv.SetStrokeLineJoin(STROKE_ROUND_JOIN)

	//cv.SetFillRule(FILL_EVEN_ODD_RULE)
	cv.SetFillColor("#888888")

	return cv
}
Beispiel #2
0
func Resize(fpath, tpath string, typ, cols, rows int) error {
	var mw *C.MagickWand = C.NewMagickWand()
	var cfpath = C.CString(fpath)
	var ctpath = C.CString(tpath)
	var etype C.ExceptionType
	defer func() {
		C.free(unsafe.Pointer(cfpath))
		C.free(unsafe.Pointer(ctpath))
	}()
	defer func() {
		C.ClearMagickWand(mw)
		C.DestroyMagickWand(mw)
	}()
	if C.MagickReadImage(mw, cfpath) == C.MagickFalse {
		goto ERR
	}

	if C.scale(mw, C.int(typ), C.int(cols), C.int(rows)) == C.MagickFalse {
		goto ERR
	}
	if C.MagickWriteImages(mw, ctpath, C.MagickTrue) == C.MagickFalse {
		goto ERR
	}
	return nil
ERR:
	etype = C.MagickGetExceptionType(mw)
	return errors.New(C.GoString(C.MagickGetException(mw, &etype)))
}
Beispiel #3
0
// Returns a new canvas object.
func New() *Canvas {
	self := &Canvas{}

	self.wand = C.NewMagickWand()
	self.drawing = C.NewDrawingWand()

	self.fg = C.NewPixelWand()
	self.bg = C.NewPixelWand()

	self.fill = C.NewPixelWand()
	self.stroke = C.NewPixelWand()

	self.SetBackgroundColor("none")

	self.SetStrokeColor("#ffffff")
	//self.SetStrokeAntialias(true)
	//self.SetStrokeWidth(1.0)
	//self.SetStrokeOpacity(1.0)
	//self.SetStrokeLineCap(STROKE_ROUND_CAP)
	//self.SetStrokeLineJoin(STROKE_ROUND_JOIN)

	self.SetFillColor("#000000")

	return self
}
Beispiel #4
0
// Returns a new canvas object.
func New() *Canvas {
	self := &Canvas{}

	self.wand = C.NewMagickWand()

	self.fg = C.NewPixelWand()
	self.bg = C.NewPixelWand()

	self.fill = C.NewPixelWand()
	self.stroke = C.NewPixelWand()

	self.drawing = C.NewDrawingWand()

	//self.SetColor("#ffffff")
	self.SetBackgroundColor("none")

	self.SetStrokeColor("#ffffff")
	self.SetStrokeAntialias(true)
	self.SetStrokeWidth(1.0)
	self.SetStrokeOpacity(1.0)
	self.SetStrokeLineCap(STROKE_ROUND_CAP)
	self.SetStrokeLineJoin(STROKE_ROUND_JOIN)

	//self.SetFillRule(FILL_EVEN_ODD_RULE)
	self.SetFillColor("#888888")

	self.text = self.NewTextProperties(true)

	return self
}
Beispiel #5
0
func Open(filename string) (img *Image, err error) {
	img = &Image{wand: C.NewMagickWand()}
	var file *os.File
	if file, err = os.Open(filename); err != nil {
		return nil, err
	}
	var data []byte
	if data, err = ioutil.ReadAll(file); err != nil {
		return nil, err
	}

	C.MagickReadImageBlob(img.wand, unsafe.Pointer(&data[0]), C.size_t(len(data)))

	return img, nil
}
Beispiel #6
0
// 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
}
Beispiel #7
0
/*
   Create a wand required for all other methods in the API. A panic() is
   thrown if there is not enough memory to allocate the wand. Use Destroy() to
   dispose of the wand when it is no longer needed.
*/
func NewMagickWand() *MagickWand {
	return &MagickWand{wand: C.NewMagickWand()}
}
Beispiel #8
0
// Public: create a new mage, associate with a new magick wand
//
// Examples:
//  InitWandEnv()
//  mage := NewMage()
//  ...
//  TermWandEnv()
func NewMage() *Mage {
	mage := &Mage{}
	mage.wand = C.NewMagickWand()
	return mage
}