Пример #1
0
// Extracts a region from the canvas.
func (cv Canvas) Crop(x int, y int, width uint, height uint) bool {
	status := C.MagickCropImage(cv.wand, C.size_t(width), C.size_t(height), C.ssize_t(x), C.ssize_t(y))
	if status == C.MagickFalse {
		return false
	}
	return true
}
Пример #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))
}
Пример #3
0
/* Extracts a region of the image. */
func (w *MagickWand) CropImage(width, height uint, x, y int) error {
	if C.MagickCropImage(w.wand, C.size_t(width), C.size_t(height), C.ssize_t(x), C.ssize_t(y)) == C.MagickFalse {
		eStr, eCode := w.Exception()
		return fmt.Errorf("CropImage() failed : [%d] %s", eStr, eCode)
	}

	return nil
}
Пример #4
0
// Extracts a region from the canvas.
func (self *Canvas) Crop(x int, y int, width uint, height uint) error {
	success := C.MagickCropImage(self.wand, C.size_t(width), C.size_t(height), C.ssize_t(x), C.ssize_t(y))

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

	return nil
}
Пример #5
0
/*
Crop() extracts a region of this image.

width: the region width
height: the region height
x: the region x offset
y: the region y offset
*/
func (this *Image) Crop(width int64, height int64, x int64, y int64) error {
	if this.magickWand == nil {
		return errors.New("error crop image:magickwand is nil")
	}

	status := C.MagickCropImage(this.magickWand, C.ulong(width), C.ulong(height), C.long(x), C.long(y))
	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 crop image: %s (ExceptionType = %d)", C.GoString(descr), etype))
	}

	return nil
}
Пример #6
0
/*
Crop() extracts a region of this image.

width: the region width
height: the region height
x: the region x offset
y: the region y offset
*/
func (this *Image) Crop(width int64, height int64, x int64, y int64) error {
	var err error = nil
	tran := this.Cat.NewTransaction("GraphicsMagickCmd", "Crop")
	defer func() {
		tran.SetStatus(err)
		tran.Complete()
	}()
	if this.magickWand == nil {
		err = errors.New("error crop image:magickwand is nil")
		return err
	}

	status := C.MagickCropImage(this.magickWand, C.ulong(width), C.ulong(height), C.long(x), C.long(y))
	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 crop image: %s (ExceptionType = %d)", C.GoString(descr), etype))
		return err
	}

	return nil
}