Exemplo n.º 1
0
func (ip *imageProcessor) blurWand(wand *imagick.MagickWand, request *ImageProcessorOptions) (err error, modified bool) {
	if request.BlurRadius != 0 {
		blurRadius := float64(wand.GetImageWidth()) * request.BlurRadius * ip.Config.MaxBlurRadiusPercentage
		if err = wand.GaussianBlurImage(blurRadius, blurRadius); err != nil {
			ip.Logger.Warn("ImageMagick error setting blur radius: %s", err)
		}
		return err, true
	}
	return nil, false
}
Exemplo n.º 2
0
func (ip *imageProcessor) scaleWand(wand *imagick.MagickWand, request *ImageProcessorOptions) (err error, modified bool) {
	currentDimensions := ImageDimensions{uint64(wand.GetImageWidth()), uint64(wand.GetImageHeight())}
	newDimensions := ip.getScaledDimensions(currentDimensions, request)

	if newDimensions == currentDimensions {
		return nil, false
	}

	if err = wand.ResizeImage(uint(newDimensions.Width), uint(newDimensions.Height), imagick.FILTER_LANCZOS, 1); err != nil {
		ip.Logger.Warn("ImageMagick error resizing image: %s", err)
		return err, true
	}

	if err = wand.SetImageInterpolateMethod(imagick.INTERPOLATE_PIXEL_BICUBIC); err != nil {
		ip.Logger.Warn("ImageMagick error setting interpoliation method: %s", err)
		return err, true
	}

	if err = wand.StripImage(); err != nil {
		ip.Logger.Warn("ImageMagick error stripping image routes and metadata")
		return err, true
	}

	if "JPEG" == wand.GetImageFormat() {
		if err = wand.SetImageInterlaceScheme(imagick.INTERLACE_PLANE); err != nil {
			ip.Logger.Warn("ImageMagick error setting the image interlace scheme")
			return err, true
		}

		if err = wand.SetImageCompression(imagick.COMPRESSION_JPEG); err != nil {
			ip.Logger.Warn("ImageMagick error setting the image compression type")
			return err, true
		}

		if err = wand.SetImageCompressionQuality(uint(ip.Config.ImageCompressionQuality)); err != nil {
			ip.Logger.Warn("sImageMagick error setting compression quality: %s", err)
			return err, true
		}
	}

	return nil, true
}