当前位置: 首页>>代码示例>>Golang>>正文


Golang Image.Resize方法代码示例

本文整理汇总了Golang中github.com/ctripcorp/nephele/imgsvr/img4g.Image.Resize方法的典型用法代码示例。如果您正苦于以下问题:Golang Image.Resize方法的具体用法?Golang Image.Resize怎么用?Golang Image.Resize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/ctripcorp/nephele/imgsvr/img4g.Image的用法示例。


在下文中一共展示了Image.Resize方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Process

func (this *ResizeRProcessor) Process(img *img4g.Image) error {
	log.Debug("process resize r")
	var err error
	tran := this.Cat.NewTransaction("Command", "ResizeR")
	defer func() {
		tran.SetStatus(err)
		tran.Complete()
	}()
	var width, height int64
	width, height, err = img.Size()
	if err != nil {
		return err
	}
	if width <= this.Width && height <= this.Height {
		return nil
	}
	var (
		x int64 = 0
		y int64 = 0
		w int64 = width
		h int64 = height
	)
	if width > this.Width && height > this.Height {
		p1 := float64(this.Width) / float64(this.Height)
		p2 := float64(width) / float64(height)
		w = 0
		h = 0
		if math.Abs(p1-p2) > 0.0001 {
			if p2 > p1 { //以高缩小
				h = height
				w = int64(math.Floor(float64(h) * p1))
				x = (width - w) / 2
			}
			if p2 < p1 { //以宽缩小
				w = width
				h = int64(math.Floor(float64(w) / p1))
				y = (height - h) / 2
			}
			err = img.Crop(w, h, x, y)
			if err != nil {
				return err
			}
		}
		err = img.Resize(this.Width, this.Height)
		return err
	} else {
		if width > this.Width {
			x = (w - this.Width) / 2
			w = this.Width
		}
		if height > this.Height {
			y = (h - this.Height) / 2
			h = this.Height
		}
		err = img.Crop(w, h, x, y)
		return err
	}

}
开发者ID:chenbk85,项目名称:nephele,代码行数:59,代码来源:resize_r.go

示例2: Process

func (p *ScaleProcessor) Process(img *img4g.Image) error {
	l4g.Debug("process scale")
	var err error
	tran := cat.Instance().NewTransaction(Image, "Scale")
	defer func() {
		tran.SetStatus(err)
		tran.Complete()
	}()
	err = img.Resize(p.Width, p.Height)
	return err
}
开发者ID:zesus19,项目名称:nephele,代码行数:11,代码来源:scaleprocessor.go

示例3: Process

func (this *ResizeCProcessor) Process(img *img4g.Image) error {
	l4g.Debug("process resize c")
	var err error
	tran := this.Cat.NewTransaction(Image, "ResizeC")
	defer func() {
		tran.SetStatus(err)
		tran.Complete()
	}()

	var width, height = this.imgWidth, this.imgHeight
	var wd, ht int64
	if width == 0 || height == 0 {
		wd, ht, err = img.Size()
		if err != nil {
			return err
		}
		width = wd
		height = ht
	}

	p1 := float64(this.Width) / float64(this.Height)
	p2 := float64(width) / float64(height)
	var (
		x int64 = 0
		y int64 = 0
		w int64 = 0
		h int64 = 0
	)
	if math.Abs(p1-p2) > 0.0001 {
		if p2 > p1 { //以高缩小
			h = height
			w = int64(math.Floor(float64(h) * p1))
			x = (width - w) / 2
		}
		if p2 < p1 { //以宽缩小
			w = width
			h = int64(math.Floor(float64(w) / p1))
			y = (height - h) / 2
		}
		err = img.Crop(w, h, x, y)
		if err != nil {
			return err
		}
	}
	err = img.Resize(this.Width, this.Height)
	return err
}
开发者ID:zesus19,项目名称:nephele,代码行数:47,代码来源:resizecprocessor.go

示例4: Process

//高固定,宽(原图比例计算),宽固定,高(原图比例计算) (压缩)
func (this *ResizeZProcessor) Process(img *img4g.Image) error {
	l4g.Debug("process resize z")
	var err error
	tran := this.Cat.NewTransaction(Image, "ResizeW")
	defer func() {
		tran.SetStatus(err)
		tran.Complete()
	}()

	var width, height = this.imgWidth, this.imgHeight
	if this.imgWidth == 0 || this.imgHeight == 0 {
		var wd, ht int64
		wd, ht, err = img.Size()
		if err != nil {
			return err
		}
		width = wd
		height = ht
	}
	p1 := float64(this.Width) / float64(this.Height)
	p2 := float64(width) / float64(height)
	w, h := this.Width, this.Height
	if p2 > p1 {
		h = int64(math.Floor(float64(this.Width) / p2))
		if int64(math.Abs(float64(h-this.Height))) < 3 {
			h = this.Height
		}
	} else {
		w = int64(math.Floor(float64(this.Height) * p2))
		if int64(math.Abs(float64(w-this.Width))) < 3 {
			w = this.Width
		}
	}
	err = img.Resize(w, h)
	return err
}
开发者ID:zesus19,项目名称:nephele,代码行数:37,代码来源:resizezprocessor.go

示例5: Process

//高固定,宽(原图比例计算),宽固定,高(原图比例计算) (压缩)
func (this *ResizeWProcessor) Process(img *img4g.Image) error {
	log.Debug("process resize w")
	var err error
	tran := this.Cat.NewTransaction("Command", "ResizeW")
	defer func() {
		tran.SetStatus(err)
		tran.Complete()
	}()
	var width, height int64
	width, height, err = img.Size()
	if err != nil {
		return err
	}

	if (width <= this.Width && height <= this.Height && this.Width != 0 && this.Height != 0) || (this.Width == 0 && height <= this.Height) || (this.Height == 0 && width <= this.Width) {
		return nil
	}

	w, h := this.Width, this.Height
	if w == 0 {
		w = width * h / height
		err = img.Resize(w, h)
		return err
	}
	if h == 0 {
		h = height * w / width
		err = img.Resize(w, h)
		return err
	}

	p1 := float64(this.Width) / float64(this.Height)
	p2 := float64(width) / float64(height)

	if p2 > p1 {
		h = int64(math.Floor(float64(this.Width) / p2))
		if int64(math.Abs(float64(h-this.Height))) < 3 {
			h = this.Height
		}
	} else {
		w = int64(math.Floor(float64(this.Height) * p2))
		if int64(math.Abs(float64(w-this.Width))) < 3 {
			w = this.Width
		}
	}
	err = img.Resize(w, h)
	return err
}
开发者ID:chenbk85,项目名称:nephele,代码行数:48,代码来源:resize_w.go


注:本文中的github.com/ctripcorp/nephele/imgsvr/img4g.Image.Resize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。