func (this *CompressLosslessly) compressJpeg(image *uploadedfile.UploadedFile) error { filename, err := processorcommand.Jpegtran(image.GetPath()) if err != nil { return err } image.SetPath(filename) return nil }
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) }
func (this *ImageOrienter) Process(image *uploadedfile.UploadedFile) error { filename, err := processorcommand.FixOrientation(image.GetPath()) if err != nil { return err } image.SetPath(filename) return nil }
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 }
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 }
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 } }