// Set up the drawingwand "dw" for the given font name, font size, and colour. // If the font or size changes sx get the new width of a space // (the magickwand is required if it is necessary to query the font metrics) func draw_setfont(mw *imagick.MagickWand, dw *imagick.DrawingWand, font string, size float64, colour string, sx *float64) { sflag := false if len(font) > 0 { dw.SetFont(font) sflag = true } if len(colour) > 0 { pw := imagick.NewPixelWand() pw.SetColor(colour) dw.SetFillColor(pw) pw.Destroy() sflag = true } if size > 0 { dw.SetFontSize(size) } // If either the font or the fontsize (or both) have changed // we need to get the size of a space again if sflag { fm := mw.QueryFontMetrics(dw, " ") *sx = fm.TextWidth } }
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 }
// The easiest (?) way to handle vertical text placement is // not to use gravity at all because then you know that all the text is // placed relative to ImageMagick's (0,0) coordinate which is the top left of // the screen and the baseline will be y=0. func draw_metrics(mw *imagick.MagickWand, dw *imagick.DrawingWand, dx *float64, dy, sx float64, text string) { mw.AnnotateImage(dw, *dx, dy, 0, text) mw.DrawImage(dw) // get the font metrics fm := mw.QueryFontMetrics(dw, text) if fm != nil { // Adjust the new x coordinate *dx += fm.TextWidth + sx } }
// make-tile creates a tileable image from an input image. // ( +clone -flop ) +append ( +clone -flip ) -append -resize 50% func make_tile(mw *imagick.MagickWand, outfile string) { mwc := mw.Clone() mwc.FlopImage() mw.AddImage(mwc) mwc.Destroy() mwc = mw.AppendImages(false) mwf := mwc.Clone() mwf.FlipImage() mwc.AddImage(mwf) mwf.Destroy() mwf = mwc.AppendImages(true) w := mwf.GetImageWidth() h := mwf.GetImageHeight() // 1 = Don't blur or sharpen image mwf.ResizeImage(w/2, h/2, imagick.FILTER_LANCZOS, 1) mwf.WriteImage(outfile) mwf.Destroy() mwc.Destroy() }
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 }