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))) }
// Destroys canvas. func (self Canvas) Destroy() error { if self.wand != nil { C.DestroyMagickWand(self.wand) self.wand = nil } if self.bg != nil { C.DestroyPixelWand(self.bg) self.bg = nil } if self.fg != nil { C.DestroyPixelWand(self.fg) self.fg = nil } if self.stroke != nil { C.DestroyPixelWand(self.stroke) self.stroke = nil } if self.fill != nil { C.DestroyPixelWand(self.fill) self.fill = nil } if self.drawing != nil { C.DestroyDrawingWand(self.drawing) self.drawing = nil } return fmt.Errorf("Nothing to destroy") }
// Deallocates memory associated with an MagickWand func (mw *MagickWand) Destroy() { if mw.mw == nil { return } mw.mw = C.DestroyMagickWand(mw.mw) C.free(unsafe.Pointer(mw.mw)) mw.mw = nil }
// Deallocates memory associated with an MagickWand func (mw *MagickWand) Destroy() { if mw.mw == nil { return } mw.mw = C.DestroyMagickWand(mw.mw) relinquishMemory(unsafe.Pointer(mw.mw)) mw.mw = nil }
// Destroys canvas. func (self Canvas) Destroy() error { if self.wand != nil { C.DestroyMagickWand(self.wand) self.wand = nil return nil } return fmt.Errorf("Nothing to destroy") //C.MagickWandTerminus() }
// Private: center the current wand on top of the new wand, after that, we only // keep the new wand. // // Params: // - newWand: new wand, probably going to be result of blankWand // - x: x position on the current wand that is the center of the new wand // - y: y position on the current wand that is the center of the new wand // // Example: // newWand := blankWand("jpg", width, height) // done := m.compositeCenter(newWand, 10, 10) // // Return boolean result of the composition func (m *Mage) compositeCenter(newWand *C.MagickWand, x, y int) bool { success := C.MagickCompositeImage( newWand, m.wand, C.OverCompositeOp, C.ssize_t(x), C.ssize_t(y)) C.DestroyMagickWand(m.wand) m.wand = newWand return mBoolean(success) }
/* DestroyWand() deallocates memory associated with this Image wand. */ func (this *Image) DestoryWand() { var err error = nil tran := this.Cat.NewTransaction("GraphicsMagickCmd", "DestoryWand") defer func() { tran.SetStatus(err) tran.Complete() }() if this.magickWand != nil { C.DestroyMagickWand(this.magickWand) this.magickWand = (*C.MagickWand)(nil) } }
// Converts the current image into a thumbnail of the specified // width and height preserving ratio. It uses Crop() to clip the // image to the specified area. // // If width or height are bigger than the current image, a centered // thumbnail will be produced. // // Is width and height are smaller than the current image, the image // will be resized and cropped, if needed. func (self *Canvas) Thumbnail(width uint, height uint) error { var ratio float64 // Normalizing image. ratio = math.Min(float64(self.Width())/float64(width), float64(self.Height())/float64(height)) if ratio < 1.0 { // Origin image is smaller than the thumbnail image. max := uint(math.Max(float64(width), float64(height))) // Empty replacement buffer with transparent background. replacement := New() replacement.SetBackgroundColor("none") replacement.Blank(max, max) // Putting original image in the center of the replacement canvas. replacement.AppendCanvas(self, int(int(width-self.Width())/2), int(int(height-self.Height())/2)) // Replacing wand C.DestroyMagickWand(self.wand) self.wand = C.CloneMagickWand(replacement.wand) } else { // Is bigger, just resizing. err := self.Resize(uint(float64(self.Width())/ratio), uint(float64(self.Height())/ratio)) if err != nil { return err } } // Now we have an image that we can use to crop the thumbnail from. err := self.Crop(int(int(self.Width()-width)/2), int(int(self.Height()-height)/2), width, height) if err != nil { return err } return nil }
// Destroys canvas. func (self *Canvas) Destroy() error { if self.bg != nil { C.DestroyPixelWand(self.bg) self.bg = nil } if self.fg != nil { C.DestroyPixelWand(self.fg) self.fg = nil } if self.stroke != nil { C.DestroyPixelWand(self.stroke) self.stroke = nil } if self.fill != nil { C.DestroyPixelWand(self.fill) self.fill = nil } if self.drawing != nil { C.DestroyDrawingWand(self.drawing) self.drawing = nil } if self.wand == nil { return errors.New("Nothing to destroy") } else { C.DestroyMagickWand(self.wand) self.wand = nil } if self.text != nil && self.text.UnderColor != nil { C.DestroyPixelWand(self.text.UnderColor) self.text.UnderColor = nil } return nil }
// Destroys canvas. func (cv Canvas) Destroy() { if cv.wand != nil { C.DestroyMagickWand(cv.wand) } C.MagickWandTerminus() }
/* Deallocates memory associated with an MagickWand. */ func (w *MagickWand) Destroy() { C.DestroyMagickWand(w.wand) }
func (img *Image) Close() { C.DestroyMagickWand(img.wand) }
/* DestroyWand() deallocates memory associated with this Image wand. */ func (this *Image) DestoryWand() { if this.magickWand != nil { C.DestroyMagickWand(this.magickWand) this.magickWand = (*C.MagickWand)(nil) } }
func (m *Mage) Destroy() { defer C.DestroyMagickWand(m.wand) }