コード例 #1
0
ファイル: user.go プロジェクト: trigrass2/wego
func (m *User) avatarLink(size int) string {
	if m.AvatarType == setting.AvatarTypePersonalized {
		if m.AvatarKey != "" {
			return fmt.Sprintf("%s", utils.GetQiniuZoomViewUrl(utils.GetQiniuPublicDownloadUrl(setting.QiniuAvatarDomain, m.AvatarKey), size, size))
		} else {
			return fmt.Sprintf("http://golanghome-public.qiniudn.com/golang_avatar.png?imageView/0/w/%s/h/%s/q/100", utils.ToStr(size), utils.ToStr(size))
		}
	} else {
		return fmt.Sprintf("%s%s?size=%s", setting.AvatarURL, m.GrEmail, utils.ToStr(size))
	}
}
コード例 #2
0
ファイル: qiniu_upload.go プロジェクト: trigrass2/wego
func QiniuImage(ctx *tango.Context) {
	var imageName = ctx.Params().Get(":path")
	var imageKey string
	var imageSize string
	if i := strings.IndexRune(imageName, '.'); i == -1 {
		return
	} else {
		imageSize = imageName[i+1:]
		if j := strings.IndexRune(imageSize, '.'); j == -1 {
			imageSize = "full"
		} else {
			imageSize = imageSize[:j]
		}
		imageKey = imageName[:i]
	}

	var image = models.Image{
		Token: imageKey,
	}
	err := models.GetByExample(&image)
	if err != nil {
		return
	}
	var imageWidth = image.Width
	var imageHeight = image.Height
	var zoomRatio = setting.ImageSizeMiddle / imageWidth
	if imageWidth > setting.ImageSizeMiddle {
		imageWidth = setting.ImageSizeMiddle
	}
	imageHeight *= zoomRatio

	var imageUrl = utils.GetQiniuPublicDownloadUrl(setting.QiniuPostDomain, imageKey)
	var zoomImageUrl = utils.GetQiniuZoomViewUrl(imageUrl, imageWidth, imageHeight)
	resp, err := http.Get(zoomImageUrl)
	if err != nil {
		return
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return
	}
	ctx.ResponseWriter.Write(body)
}