MCPcopy
hub / github.com/gographics/imagick / textEffect1

Function textEffect1

examples/text_effects/main.go:40–90  ·  view source on GitHub ↗

Text effect 1 - shadow effect using MagickShadowImage NOTE - if an image has a transparent background, adding a border of any colour other than "none" will remove all the transparency and replace it with the border's colour

()

Source from the content-addressed store, hash-verified

38// NOTE - if an image has a transparent background, adding a border of any colour other
39// than "none" will remove all the transparency and replace it with the border's colour
40func textEffect1() {
41 imagick.Initialize()
42 defer imagick.Terminate()
43 mw := imagick.NewMagickWand()
44 defer mw.Destroy()
45 dw := imagick.NewDrawingWand()
46 defer dw.Destroy()
47 pw := imagick.NewPixelWand()
48 defer pw.Destroy()
49 pw.SetColor("none")
50 // Create a new transparent image
51 mw.NewImage(350, 100, pw)
52 // Set up a 72 point white font
53 pw.SetColor("white")
54 dw.SetFillColor(pw)
55 dw.SetFont("Verdana-Bold-Italic")
56 dw.SetFontSize(72)
57 // Add a black outline to the text
58 pw.SetColor("black")
59 dw.SetStrokeColor(pw)
60 // Turn antialias on - not sure this makes a difference
61 dw.SetTextAntialias(true)
62 // Now draw the text
63 dw.Annotation(25, 65, "Magick")
64 // Draw the image on to the mw
65 mw.DrawImage(dw)
66 // Trim the image down to include only the text
67 mw.TrimImage(0)
68 // equivalent to the command line +repage
69 mw.ResetImagePage("")
70 // Make a copy of the text image
71 cw := mw.Clone()
72 // Set the background colour to blue for the shadow
73 pw.SetColor("blue")
74 mw.SetImageBackgroundColor(pw)
75 // Opacity is a real number indicating (apparently) percentage
76 mw.ShadowImage(70, 4, 5, 5)
77 // Composite the text on top of the shadow
78 mw.CompositeImage(cw, imagick.COMPOSITE_OP_OVER, 5, 5)
79 cw.Destroy()
80 cw = imagick.NewMagickWand()
81 defer cw.Destroy()
82 // Create a new image the same size as the text image and put a solid colour
83 // as its background
84 pw.SetColor("rgb(125,215,255)")
85 cw.NewImage(mw.GetImageWidth(), mw.GetImageHeight(), pw)
86 // Now composite the shadowed text over the plain background
87 cw.CompositeImage(mw, imagick.COMPOSITE_OP_OVER, 0, 0)
88 // and write the result
89 cw.WriteImage("text_shadow.png")
90}
91
92// Text effect 2 - tiled text using the builtin checkerboard pattern
93// Anthony's Tiled Font effect

Callers 1

mainFunction · 0.85

Calls 15

DestroyMethod · 0.95
DestroyMethod · 0.95
DestroyMethod · 0.95
SetColorMethod · 0.95
NewImageMethod · 0.95
SetFillColorMethod · 0.95
SetFontMethod · 0.95
SetFontSizeMethod · 0.95
SetStrokeColorMethod · 0.95
SetTextAntialiasMethod · 0.95
AnnotationMethod · 0.95
DrawImageMethod · 0.95

Tested by

no test coverage detected