Esempio n. 1
0
func (this *ProcChainBuilder) getLogoWaterMarkProcessor(channel string, params map[string]string) (proc.ImageProcessor, error) {
	dissolve := this.getLogoDissolve(channel, params)
	logodir, err := data.GetLogodir(channel)
	if err != nil {
		return nil, err
	}
	wn, _ := params["wn"]
	wl, _ := params["wl"]
	if wn == "" {
		defaultlogo, err := data.GetDefaultLogo(channel)
		if err != nil {
			return nil, err
		}
		arr := strings.Split(defaultlogo, ",")
		if len(arr) == 2 {
			wn = arr[0]
			wl = arr[1]
		}
	}
	if wn == "" {
		return nil, nil
	}
	//check watermarkname
	logonames, err := data.GetLogoNames(channel)
	if err != nil {
		return nil, err
	}
	if !strings.Contains(logonames, JoinString(",", wn, ",")) {
		return nil, errors.New(JoinString("channel: ", channel, ", reason: not support watermark ", wn))
	}
	//check size
	lesswidth, err := data.GetImagelesswidthForLogo(channel)
	if err != nil {
		return nil, err
	}
	lessheight, err := data.GetImagelessheightForLogo(channel)
	if err != nil {
		return nil, err
	}
	if lesswidth > 0 || lessheight > 0 {
		widthVal, _ := params[":3"]
		heightVal, _ := params[":4"]
		w, _ := strconv.ParseInt(widthVal, 10, 64)
		h, _ := strconv.ParseInt(heightVal, 10, 64)
		if !(w >= lesswidth && h >= lessheight) {
			return nil, nil
		}
	}
	l, err := strconv.Atoi(wl)
	if err != nil {
		l = 9
	}
	var path = logodir + wn + ".png"
	bts, err := GetImage("NFS", path, this.Cat)
	if err != nil {
		return nil, err
	}
	logo := &img4g.Image{Format: "png", Blob: bts, Cat: this.Cat}
	return &proc.WaterMarkProcessor{Logo: logo, Location: l, Dissolve: dissolve, Cat: this.Cat, WaterMarkType: "WaterMark"}, nil
}
Esempio n. 2
0
func (this *ProcChainBuilder) getDigitalWatermarkProcessor(channel string, params map[string]string) (proc.ImageProcessor, error) {
	dwm, _ := params["dwm"]
	if dwm == "" {
		return nil, nil
	}
	copyrightdir, err := data.GetLogodir(channel)
	if err != nil {
		return nil, err
	}
	bts, err := GetImage("NFS", copyrightdir+"copy.jpg", this.Cat)
	if err != nil {
		return nil, err
	}
	copyright := &img4g.Image{Format: "jpg", Blob: bts, Cat: this.Cat}

	return &proc.DigitalWatermarkProcessor{copyright, this.Cat}, nil
}