當前位置: 首頁>>代碼示例>>Golang>>正文


Golang img4g.Image類代碼示例

本文整理匯總了Golang中github.com/ctripcorp/nephele/imgsvr/img4g.Image的典型用法代碼示例。如果您正苦於以下問題:Golang Image類的具體用法?Golang Image怎麽用?Golang Image使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Image類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Process

func (this *FormatProcessor) Process(img *img4g.Image) error {
	log.WithFields(log.Fields{
		"format": this.Format,
	}).Debug("process format")
	err := img.SetFormat(this.Format)
	return err
}
開發者ID:shitfSign,項目名稱:nephele,代碼行數:7,代碼來源:formatprocessor.go

示例2: getLocation

func getLocation(location int, img *img4g.Image, logo *img4g.Image) (int64, int64, error) {
	var (
		x int64 = 0
		y int64 = 0
	)
	width, height, err := img.Size()
	if err != nil {
		return 0, 0, err
	}
	logowidth, logoheight, err := logo.Size()
	if err != nil {
		return 0, 0, err
	}
	switch location {
	case 1:
		x, y = 0, 0
	case 2:
		x, y = (width-logowidth)/2, 0
	case 3:
		x, y = width-logowidth, 0
	case 4:
		x, y = 0, (height-logoheight)/2
	case 5:
		x, y = (width-logowidth)/2, (height-logoheight)/2
	case 6:
		x, y = width-logowidth, (height-logoheight)/2
	case 7:
		x, y = 0, height-logoheight
	case 8:
		x, y = (width-logowidth)/2, height-logoheight
	case 9:
		x, y = width-logowidth, height-logoheight
	}
	return x, y, nil
}
開發者ID:zesus19,項目名稱:nephele,代碼行數:35,代碼來源:watermarkprocessor.go

示例3: Process

func (this *QualityProcessor) Process(img *img4g.Image) error {
	log.WithFields(log.Fields{
		"quality": this.Quality,
	}).Debug("process quality")
	err := img.SetCompressionQuality(this.Quality)
	return err
}
開發者ID:shitfSign,項目名稱:nephele,代碼行數:7,代碼來源:qualityprocessor.go

示例4: Process

func (this *WaterMarkProcessor) Process(img *img4g.Image) error {
	l4g.Debug("process watermark")
	var err error = nil
	tran := this.Cat.NewTransaction(Image, "Watermark")

	defer func() {
		this.Logo.DestoryWand()
		tran.SetStatus(err)
		tran.Complete()
	}()
	this.Logo.CreateWand()
	if this.Location == 0 {
		this.Location = 9
	}
	if this.Location < 1 || this.Location > 9 {
		err = errors.New("Logo location(" + string(this.Location) + ") isn't right!")
		return err
	}
	var x, y int64
	x, y, err = getLocation(this.Location, img, this.Logo)
	if err != nil {
		return err
	}

	if this.Dissolve > 0 && this.Dissolve < 100 {
		this.Logo.Dissolve(this.Dissolve)
	}

	err = img.Composite(this.Logo, x, y)
	return err
}
開發者ID:zesus19,項目名稱:nephele,代碼行數:31,代碼來源:watermarkprocessor.go

示例5: 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

示例6: Process

func (this *QualityProcessor) Process(img *img4g.Image) error {
	l4g.Debug("process quality")
	var err error
	tran := this.Cat.NewTransaction(Image, "Quality")
	defer func() {
		tran.SetStatus(err)
		tran.Complete()
	}()
	err = img.SetCompressionQuality(this.Quality)
	return err
}
開發者ID:zesus19,項目名稱:nephele,代碼行數:11,代碼來源:qualityprocessor.go

示例7: Process

func (this *StripProcessor) Process(img *img4g.Image) error {
	l4g.Debug("process strip")
	var err error
	tran := this.Cat.NewTransaction(Image, "Strip")
	defer func() {
		tran.SetStatus(err)
		tran.Complete()
	}()
	err = img.Strip()
	return err
}
開發者ID:zesus19,項目名稱:nephele,代碼行數:11,代碼來源:stripprocessor.go

示例8: Process

func (this *FormatProcessor) Process(img *img4g.Image) error {
	l4g.Debug("process format")
	var err error
	tran := this.Cat.NewTransaction(Image, "Format")
	defer func() {
		tran.SetStatus(err)
		tran.Complete()
	}()
	err = img.SetFormat(this.Format)
	return err
}
開發者ID:zesus19,項目名稱:nephele,代碼行數:11,代碼來源:formatprocessor.go

示例9: Process

func (this *RotateProcessor) Process(img *img4g.Image) error {
	l4g.Debug("process rotate ")
	var err error
	tran := this.Cat.NewTransaction(Image, "Rotate")
	defer func() {
		tran.SetStatus(err)
		tran.Complete()
	}()
	err = img.Rotate(this.Degress)
	return err
}
開發者ID:zesus19,項目名稱:nephele,代碼行數:11,代碼來源:rotateprocessor.go

示例10: 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

示例11: Process

func (this *DigitalWatermarkProcessor) Process(img *img4g.Image) error {
	log.Debug("process digitalwatermark")
	var err error = nil

	format, err := img.GetFormat()
	if err != nil {
		return err
	}
	if strings.ToLower(format) != "jpg" && strings.ToLower(format) != "jpeg" {
		info := make(map[string]string)
		info["format"] = format
		logEvent(this.Cat, "DigitalWatermarkRefuse", "NotSupportFormat", info)
		return nil
	}

	width, err := img.GetWidth()
	if err != nil {
		return err
	}
	if width < 256 {
		info := make(map[string]string)
		info["width"] = strconv.Itoa(int(width))
		logEvent(this.Cat, "DigitalWatermarkRefuse", "NotSupportSize", info)
		return nil
	}

	height, err := img.GetHeight()
	if err != nil {
		return err
	}
	if height < 256 {
		info := make(map[string]string)
		info["height"] = strconv.Itoa(int(height))
		logEvent(this.Cat, "DigitalWatermarkRefuse", "NotSupportSize", info)
		return nil
	}

	upr := ((int(math.Min(float64(width), float64(height))) / 100.0) + 1) * 100
	tran := this.Cat.NewTransaction("DigitalWatermark", "Min(width, height)<"+strconv.Itoa(int(upr)))
	tran.AddData("size", "width: "+strconv.Itoa(int(width))+"height: "+strconv.Itoa(int(height)))
	defer func() {
		this.Copyright.DestoryWand()
		tran.SetStatus(err)
		tran.Complete()
	}()
	if err = this.Copyright.CreateWand(); err != nil {
		return err
	}
	err = img.DigitalWatermark(this.Copyright)

	return err
}
開發者ID:cannonhuang,項目名稱:nephele,代碼行數:52,代碼來源:digitalwatermarkprocessor.go

示例12: Process

//高固定,寬(原圖比例計算),寬固定,高(原圖比例計算) (壓縮)
func (this *ResizeWProcessor) Process(img *img4g.Image) error {
	l4g.Debug("process resize w")
	var err error
	tran := this.Cat.NewTransaction(Image, "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 {
		return nil
	}
	z := ResizeZProcessor{this.Width, this.Height, this.Cat, width, height}
	err = z.Process(img)
	return err
}
開發者ID:zesus19,項目名稱:nephele,代碼行數:21,代碼來源:resizewprocessor.go

示例13: Process

func (this *ResizeRProcessor) Process(img *img4g.Image) error {
	l4g.Debug("process resize r")
	var err error
	tran := this.Cat.NewTransaction(Image, "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
	}
	if width > this.Width && height > this.Height {
		c := ResizeCProcessor{this.Width, this.Height, this.Cat, width, height}
		err = c.Process(img)
		return err
	}
	var (
		x int64 = 0
		y int64 = 0
		w int64 = width
		h int64 = height
	)
	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:zesus19,項目名稱:nephele,代碼行數:38,代碼來源:resizerprocessor.go

示例14: 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

示例15: 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


注:本文中的github.com/ctripcorp/nephele/imgsvr/img4g.Image類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。