Exemplo n.º 1
0
func (this *ImageScaler) Process(image *uploadedfile.UploadedFile) error {
	switch image.GetMime() {
	case "image/jpeg", "image/jpg":
		return this.scaleJpeg(image)
	case "image/png":
		return this.scalePng(image)
	case "image/gif":
		return this.scaleGif(image)
	}

	return errors.New("Unsuported filetype")
}
Exemplo n.º 2
0
func (s *Server) buildThumbResponse(upload *uploadedfile.UploadedFile) (map[string]interface{}, error) {
	factory := imagestore.NewFactory(s.Config)
	thumbsResp := map[string]interface{}{}

	for _, t := range upload.GetThumbs() {
		thumbName := fmt.Sprintf("%s/%s", upload.GetHash(), t.GetName())
		tObj := factory.NewStoreObject(thumbName, upload.GetMime(), "thumbnail")
		err := tObj.Store(t, s.ImageStore)
		if err != nil {
			return nil, err
		}

		thumbsResp[t.GetName()] = tObj.Url
	}

	return thumbsResp, nil
}