Exemplo n.º 1
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.º 2
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.º 3
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.º 4
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
	}
}