Esempio n. 1
0
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))
	}
}
Esempio n. 2
0
func QiniuImageFilter(ctx *context.Context) {
	var imageName = path.Base(ctx.Request.RequestURI)
	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 := image.Read("Token")
	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)
}