// Changes the size of the canvas using specified filter and blur, returns true on success. func (self *Canvas) ResizeWithFilter(width uint, height uint, filter uint, blur float32) error { if width == 0 && height == 0 { return errors.New("Please specify at least one of dimensions") } if width == 0 || height == 0 { origHeight := uint(C.MagickGetImageHeight(self.wand)) origWidth := uint(C.MagickGetImageWidth(self.wand)) if width == 0 { ratio := float32(origHeight) / float32(height) width = uint(float32(origWidth) / ratio) } if height == 0 { ratio := float32(origWidth) / float32(width) height = uint(float32(origHeight) / ratio) } } success := C.MagickResizeImage(self.wand, C.size_t(width), C.size_t(height), C.FilterTypes(filter), C.double(blur)) if success == C.MagickFalse { return fmt.Errorf("Could not resize: %s", self.Error()) } return nil }
// ResizeBlur returns a new image resized to the given dimensions using the provided // filter and blur factor (where > 1 is blurry, < 1 is sharp). If width or height is // < 0, it's calculated proportionally to the other dimension. If both of them are < 0, // an error is returned. func (im *Image) ResizeBlur(width, height int, filter Filter, blur float64) (*Image, error) { var data C.ResizeData if width < 0 { if height < 0 { return nil, fmt.Errorf("invalid resize %dx%d", width, height) } h := float64(im.Height()) var ratio float64 if h != 0 { ratio = float64(im.Width()) / h } width = int(float64(height) * ratio) } if height < 0 { if width < 0 { return nil, fmt.Errorf("invalid resize %dx%d", width, height) } var ratio float64 w := float64(im.Width()) if w != 0 { ratio = float64(im.Height()) / w } height = int(float64(width) * ratio) } data.columns = C.ulong(width) data.rows = C.ulong(height) data.filter = C.FilterTypes(filter) data.blur = C.double(blur) return im.applyDataFunc("resizing", C.ImageDataFunc(C.resizeImage), &data) }
// ResizeBlur returns a new image resized to the given dimensions using the provided // filter and blur factor (where > 1 is blurry, < 1 is sharp). func (im *Image) ResizeBlur(width, height int, filter Filter, blur float64) (*Image, error) { var data C.ResizeData data.columns = C.ulong(width) data.rows = C.ulong(height) data.filter = C.FilterTypes(filter) data.blur = C.double(blur) return im.applyDataFunc("resizing", C.ImageDataFunc(C.resizeImage), &data) }
/* Scales an image to the desired dimensions. */ func (w *MagickWand) ResizeImage(columns, rows uint, filter int, blur float64) error { if C.MagickResizeImage(w.wand, C.size_t(columns), C.size_t(rows), C.FilterTypes(filter), C.double(blur)) == C.MagickFalse { eStr, eCode := w.Exception() return fmt.Errorf("Resize() failed : [%d] %s", eStr, eCode) } return nil }