Exemplo n.º 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))
}
Exemplo n.º 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
}
Exemplo n.º 3
0
/*
Returns the image width
*/
func (this *Image) GetWidth() (int64, error) {
	if this.magickWand == nil {
		return 0, errors.New("error get image height:magickwand is nil")
	}

	width, err := C.MagickGetImageWidth(this.magickWand)

	return int64(width), err
}
Exemplo n.º 4
0
/*
Returns the image width
*/
func (this *Image) GetWidth() (int64, error) {
	var err error = nil
	tran := this.Cat.NewTransaction("GraphicsMagickCmd", "GetWidth")
	defer func() {
		tran.SetStatus(err)
		tran.Complete()
	}()
	if this.magickWand == nil {
		err = errors.New("error get image height:magickwand is nil")
		return 0, err
	}
	width, err := C.MagickGetImageWidth(this.magickWand)

	return int64(width), err
}
Exemplo n.º 5
0
// Returns canvas' width.
func (cv Canvas) Width() uint {
	return uint(C.MagickGetImageWidth(cv.wand))
}
Exemplo n.º 6
0
// Returns canvas' width.
func (self *Canvas) Width() uint {
	return uint(C.MagickGetImageWidth(self.wand))
}
Exemplo n.º 7
0
/* Gets the image width. */
func (w *MagickWand) ImageWidth() uint {
	return uint(C.MagickGetImageWidth(w.wand))
}
Exemplo n.º 8
0
Arquivo: mage.go Projeto: dqminh/mage
// Public: get current width of the image
//
// Examples:
//  im = NewMage()
//  original, err := ioutil.ReadFile("test.jpg")
//  im.Width()
func (m *Mage) Width() int {
	return int(C.MagickGetImageWidth(m.wand))
}