Пример #1
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))
}
Пример #2
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
}
Пример #3
0
/*
Returns the image height
*/
func (this *Image) GetHeight() (int64, error) {
	if this.magickWand == nil {
		return 0, errors.New("error get image height:magickwand is nil")
	}

	height, err := C.MagickGetImageHeight(this.magickWand)

	return int64(height), err
}
Пример #4
0
/*
Returns the image height
*/
func (this *Image) GetHeight() (int64, error) {
	var err error = nil
	tran := this.Cat.NewTransaction("GraphicsMagickCmd", "GetHeight")
	defer func() {
		tran.SetStatus(err)
		tran.Complete()
	}()
	if this.magickWand == nil {
		err = errors.New("error get image height:magickwand is nil")
		return 0, err
	}

	height, err := C.MagickGetImageHeight(this.magickWand)

	return int64(height), err
}
Пример #5
0
// Returns canvas' height.
func (cv Canvas) Height() uint {
	return uint(C.MagickGetImageHeight(cv.wand))
}
Пример #6
0
// Returns canvas' height.
func (self *Canvas) Height() uint {
	return uint(C.MagickGetImageHeight(self.wand))
}
Пример #7
0
/* Gets the image height. */
func (w *MagickWand) ImageHeight() uint {
	return uint(C.MagickGetImageHeight(w.wand))
}
Пример #8
0
// Public: get current height of the image
//
// Examples:
//  im = NewMage()
//  original, err := ioutil.ReadFile("test.jpg")
//  im.Height()
func (m *Mage) Height() int {
	return int(C.MagickGetImageHeight(m.wand))
}