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)) }
// 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 }
/* 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 }
/* 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 }
// Returns canvas' width. func (cv Canvas) Width() uint { return uint(C.MagickGetImageWidth(cv.wand)) }
// Returns canvas' width. func (self *Canvas) Width() uint { return uint(C.MagickGetImageWidth(self.wand)) }
/* Gets the image width. */ func (w *MagickWand) ImageWidth() uint { return uint(C.MagickGetImageWidth(w.wand)) }
// 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)) }