Exemplo n.º 1
0
func (this *ImageOrienter) Process(image *uploadedfile.UploadedFile) error {
	filename, err := processorcommand.FixOrientation(image.GetPath())
	if err != nil {
		return err
	}

	image.SetPath(filename)

	return nil
}
Exemplo n.º 2
0
func (this *CompressLosslessly) compressJpeg(image *uploadedfile.UploadedFile) error {
	filename, err := processorcommand.Jpegtran(image.GetPath())
	if err != nil {
		return err
	}

	image.SetPath(filename)

	return nil
}
Exemplo n.º 3
0
func (this *OCRRunner) Process(image *uploadedfile.UploadedFile) error {
	result, err := this.Command.Run(image.GetPath())
	if err != nil {
		log.Printf("Error running OCR: %s", err.Error())
		return err
	}

	image.SetOCRText(result.Text)

	return nil
}
Exemplo n.º 4
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.º 5
0
func (this *ExifStripper) Process(image *uploadedfile.UploadedFile) error {
	if !image.IsJpeg() {
		return nil
	}

	err := processorcommand.StripMetadata(image.GetPath())
	if err != nil {
		return err
	}

	return nil
}
Exemplo n.º 6
0
func (this *ImageScaler) scalePng(image *uploadedfile.UploadedFile) error {
	filename, err := processorcommand.ConvertToJpeg(image.GetPath())
	if err != nil {
		return err
	}

	image.SetPath(filename)
	image.SetMime("image/jpeg")
	return this.scaleJpeg(image)
}
Exemplo n.º 7
0
func (this *CompressLosslessly) Process(image *uploadedfile.UploadedFile) error {
	if image.IsJpeg() {
		return this.compressJpeg(image)
	}

	if image.IsPng() {
		return this.compressPng(image)
	}

	if image.IsGif() {
		return nil
	}

	return errors.New("Unsuported filetype")
}
Exemplo n.º 8
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
}
Exemplo n.º 9
0
func (this *ImageScaler) scaleJpeg(image *uploadedfile.UploadedFile) error {
	filename, err := processorcommand.Quality(image.GetPath(), 90)
	if err != nil {
		return err
	}

	image.SetPath(filename)
	size, err := image.FileSize()
	if size < this.targetSize {
		return nil
	}

	filename, err = processorcommand.Quality(image.GetPath(), 70)
	if err != nil {
		return err
	}

	image.SetPath(filename)
	size, err = image.FileSize()
	if size < this.targetSize {
		return nil
	}

	percent := 90
	if (size - this.targetSize) >= (15 * 1024 * 1024) {
		percent = 30
	} else if (size - this.targetSize) >= (10 * 1024 * 1024) {
		percent = 40
	} else if (size - this.targetSize) >= (5 * 1024 * 1024) {
		percent = 60
	}

	for {
		filename, err = processorcommand.ResizePercent(image.GetPath(), percent)
		if err != nil {
			return err
		}

		image.SetPath(filename)
		size, err := image.FileSize()
		if err != nil {
			return err
		} else if size == 0 || percent < 10 {
			return errors.New("Could not scale image to desired filesize")
		} else if size < this.targetSize {
			return nil
		}

		percent -= 10
	}
}