Example #1
0
// Changes the size of the canvas, returns true on success.
func (cv Canvas) Resize(width uint, height uint) bool {
	status := C.MagickResizeImage(cv.wand, C.size_t(width), C.size_t(height), C.GaussianFilter, C.double(1.0))
	if status == C.MagickFalse {
		return false
	}
	return true
}
Example #2
0
func (img *Image) Resize(width int, height int) {
	wand := img.wand

	cur_width := float64(C.MagickGetImageWidth(wand))
	cur_height := float64(C.MagickGetImageHeight(wand))

	r_width := cur_width / float64(width)
	r_height := cur_height / float64(height)

	ratio := r_height
	if r_width < r_height {
		ratio = r_width
	}

	dest_width := cur_width / ratio
	dest_height := cur_height / ratio

	crop_x := int((dest_width - float64(width)) / 2)
	crop_y := int((dest_height - float64(height)) / 2)

	if r_width > 5 && r_height > 5 {
		C.MagickSampleImage(wand, C.size_t(dest_width*5), C.size_t(dest_height*5))
	}
	C.MagickResizeImage(wand, C.size_t(dest_width), C.size_t(dest_height), C.LanczosFilter, 1)
	C.MagickCropImage(wand, C.size_t(width), C.size_t(height), C.ssize_t(crop_x), C.ssize_t(crop_y))
}
Example #3
0
// 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
}
Example #4
0
/* 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
}
Example #5
0
File: mage.go Project: dqminh/mage
// Private: resize the current image to new width and height
//
// Params:
// - width: width of the new image
// - height: height of the new image
//
// Examples:
//  m.resize(100, 100)
func (m *Mage) resize(width, height int) bool {
	return mBoolean(C.MagickResizeImage(
		m.wand,
		C.size_t(width),
		C.size_t(height),
		C.LanczosFilter,
		C.double(1.0)))
}
Example #6
0
// Changes the size of the canvas, returns true on success.
func (self *Canvas) Resize(width uint, height uint) error {
	success := C.MagickResizeImage(self.wand, C.size_t(width), C.size_t(height), C.GaussianFilter, C.double(1.0))

	if success == C.MagickFalse {
		return fmt.Errorf("Could not resize: %s", self.Error())
	}

	return nil
}
Example #7
0
func (this *Image) Resize(width int64, height int64) error {
	if this.magickWand == nil {
		return errors.New("error resizing image:magickwand is nil")
	}

	status := C.MagickResizeImage(this.magickWand, C.ulong(width), C.ulong(height), C.CubicFilter, 0.5)
	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 resizing image: %s (ExceptionType = %d)", C.GoString(descr), etype))
	}

	return nil
}
Example #8
0
/*
Resize() resizes the size of this image to the given dimensions.

width: width of the resized image
height: height of the resized image
*/
func (this *Image) Resize(width int64, height int64) error {
	var err error = nil
	tran := this.Cat.NewTransaction("GraphicsMagickCmd", "Resize")
	defer func() {
		tran.SetStatus(err)
		tran.Complete()
	}()
	if this.magickWand == nil {
		err = errors.New("error resizing image:magickwand is nil")
		return err
	}

	status := C.MagickResizeImage(this.magickWand, C.ulong(width), C.ulong(height), C.CubicFilter, 0.5)
	if status == 0 {
		var etype int
		descr := C.MagickGetException(this.magickWand, (*C.ExceptionType)(unsafe.Pointer(&etype)))
		defer C.MagickRelinquishMemory(unsafe.Pointer(descr))
		err = errors.New(fmt.Sprintf("error resizing image: %s (ExceptionType = %d)", C.GoString(descr), etype))
		return err
	}

	return nil
}