本文整理汇总了Golang中github.com/rafikk/imagick/imagick.NewMagickWand函数的典型用法代码示例。如果您正苦于以下问题:Golang NewMagickWand函数的具体用法?Golang NewMagickWand怎么用?Golang NewMagickWand使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewMagickWand函数的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
imagick.Initialize()
defer imagick.Terminate()
mw := imagick.NewMagickWand()
defer mw.Destroy()
lw := imagick.NewMagickWand()
defer lw.Destroy()
pw := imagick.NewPixelWand()
defer pw.Destroy()
dw := imagick.NewDrawingWand()
defer dw.Destroy()
// Create the initial 640x480 transparent canvas
pw.SetColor("none")
mw.NewImage(640, 480, pw)
pw.SetColor("white")
dw.SetFillColor(pw)
dw.RoundRectangle(15, 15, 624, 464, 15, 15)
mw.DrawImage(dw)
lw.ReadImage("logo:")
// Note that MagickSetImageCompose is usually only used for the MagickMontageImage
// function and isn't used or needed by MagickCompositeImage
mw.CompositeImage(lw, imagick.COMPOSITE_OP_SRC_IN, 0, 0)
/* Write the new image */
mw.WriteImage("mask_result.png")
}
开发者ID:rafikk,项目名称:imagick,代码行数:30,代码来源:main.go
示例2: textEffect1
// 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
func textEffect1() {
imagick.Initialize()
defer imagick.Terminate()
mw := imagick.NewMagickWand()
defer mw.Destroy()
dw := imagick.NewDrawingWand()
defer dw.Destroy()
pw := imagick.NewPixelWand()
defer pw.Destroy()
pw.SetColor("none")
// Create a new transparent image
mw.NewImage(350, 100, pw)
// Set up a 72 point white font
pw.SetColor("white")
dw.SetFillColor(pw)
dw.SetFont("Verdana-Bold-Italic")
dw.SetFontSize(72)
// Add a black outline to the text
pw.SetColor("black")
dw.SetStrokeColor(pw)
// Turn antialias on - not sure this makes a difference
dw.SetTextAntialias(true)
// Now draw the text
dw.Annotation(25, 65, "Magick")
// Draw the image on to the mw
mw.DrawImage(dw)
// Trim the image down to include only the text
mw.TrimImage(0)
// equivalent to the command line +repage
mw.ResetImagePage("")
// Make a copy of the text image
cw := mw.Clone()
// Set the background colour to blue for the shadow
pw.SetColor("blue")
mw.SetImageBackgroundColor(pw)
// Opacity is a real number indicating (apparently) percentage
mw.ShadowImage(70, 4, 5, 5)
// Composite the text on top of the shadow
mw.CompositeImage(cw, imagick.COMPOSITE_OP_OVER, 5, 5)
cw.Destroy()
cw = imagick.NewMagickWand()
defer cw.Destroy()
// Create a new image the same size as the text image and put a solid colour
// as its background
pw.SetColor("rgb(125,215,255)")
cw.NewImage(mw.GetImageWidth(), mw.GetImageHeight(), pw)
// Now composite the shadowed text over the plain background
cw.CompositeImage(mw, imagick.COMPOSITE_OP_OVER, 0, 0)
// and write the result
cw.WriteImage("text_shadow.png")
}
开发者ID:rafikk,项目名称:imagick,代码行数:54,代码来源:main.go
示例3: textEffect2
// Text effect 2 - tiled text using the builtin checkerboard pattern
// Anthony's Tiled Font effect
func textEffect2() {
imagick.Initialize()
defer imagick.Terminate()
mw := imagick.NewMagickWand()
defer mw.Destroy()
dw := imagick.NewDrawingWand()
defer dw.Destroy()
pw := imagick.NewPixelWand()
defer pw.Destroy()
setTilePattern(dw, "#check", "pattern:checkerboard")
pw.SetColor("lightblue")
// Create a new transparent image
mw.NewImage(320, 100, pw)
// Set up a 72 point font
dw.SetFont("Verdana-Bold-Italic")
dw.SetFontSize(72)
// Now draw the text
dw.Annotation(28, 68, "Magick")
// Draw the image on to the mw
mw.DrawImage(dw)
// Trim the image
mw.TrimImage(0)
// Add a transparent border
pw.SetColor("lightblue")
mw.BorderImage(pw, 5, 5)
// and write it
mw.WriteImage("text_pattern.png")
}
开发者ID:rafikk,项目名称:imagick,代码行数:30,代码来源:main.go
示例4: ProcessImage
// The public method for processing an image. The method receives an original
// image and options and returns the processed image.
func (ip *imageProcessor) ProcessImage(image *Image, request *ImageProcessorOptions) *Image {
processedImage := Image{}
wand := imagick.NewMagickWand()
defer wand.Destroy()
wand.ReadImageBlob(image.Bytes)
err, scaleModified := ip.scaleWand(wand, request)
if err != nil {
ip.Logger.Warn("Error scaling image: %s", err)
return nil
}
err, blurModified := ip.blurWand(wand, request)
if err != nil {
ip.Logger.Warn("Error blurring image: %s", err)
return nil
}
if !scaleModified && !blurModified {
processedImage.Bytes = image.Bytes
} else {
processedImage.Bytes = wand.GetImageBlob()
}
processedImage.MimeType = fmt.Sprintf("image/%s", strings.ToLower(wand.GetImageFormat()))
return &processedImage
}
开发者ID:jeberly,项目名称:halfshell,代码行数:30,代码来源:image_processor.go
示例5: example2
// Example 2
// Rotate logo: 30 degrees around the point (300,100)
// Since rotation is done around the origin, we must translate
// the point (300,100) up to the origin, do the rotation, and
// then translate back again
//
func example2() {
imagick.Initialize()
defer imagick.Terminate()
t1 := make([]float64, 6)
r := make([]float64, 6)
t2 := make([]float64, 6)
temp := make([]float64, 6)
result := make([]float64, 6)
mw := imagick.NewMagickWand()
defer mw.Destroy()
mw.ReadImage("logo:")
// Initialize the required affines
// translate (300,100) to origin
set_translate_affine(t1, -300, -100)
// rotate clockwise by 30 degrees
set_rotate_affine(r, 30)
// translate back again
set_translate_affine(t2, 300, 100)
// Now multiply the affine sequence
// temp = t1*r
affine_multiply(temp, t1, r)
// result = temp*t2
affine_multiply(result, temp, t2)
mw.DistortImage(imagick.DISTORTION_AFFINE_PROJECTION, result, false)
mw.WriteImage("logo_affine_2.jpg")
}
开发者ID:rafikk,项目名称:imagick,代码行数:38,代码来源:main.go
示例6: textEffect7
// Text effect 7 - Polar distortion
func textEffect7() {
imagick.Initialize()
defer imagick.Terminate()
// This one uses d_args[0]
mw := imagick.NewMagickWand()
defer mw.Destroy()
dw := imagick.NewDrawingWand()
defer dw.Destroy()
pw := imagick.NewPixelWand()
defer pw.Destroy()
// Create a 320x200 transparent canvas
pw.SetColor("none")
mw.NewImage(320, 200, pw)
// Set up a 72 point font
dw.SetFont("Verdana-Bold-Italic")
dw.SetFontSize(72)
// Now draw the text
dw.Annotation(25, 65, "Magick")
// Draw the image on to the mw
mw.DrawImage(dw)
d_args[0] = 0.0
// DON'T FORGET to set the correct number of arguments here
mw.DistortImage(imagick.DISTORTION_POLAR, d_args, true)
//mw.ResetImagePage("")
// Trim the image again
mw.TrimImage(0)
// Add the border
pw.SetColor("none")
mw.BorderImage(pw, 10, 10)
// and write it
mw.WriteImage("text_polar.png")
}
开发者ID:rafikk,项目名称:imagick,代码行数:33,代码来源:main.go
示例7: textEffect4
// Text effect 4 - bevelled font http://www.imagemagick.org/Usage/fonts/#bevel
func textEffect4() {
imagick.Initialize()
defer imagick.Terminate()
mw := imagick.NewMagickWand()
defer mw.Destroy()
dw := imagick.NewDrawingWand()
defer dw.Destroy()
pw := imagick.NewPixelWand()
defer pw.Destroy()
// Create a 320x100 canvas
pw.SetColor("gray")
mw.NewImage(320, 100, pw)
// Set up a 72 point font
dw.SetFont("Verdana-Bold-Italic")
dw.SetFontSize(72)
// Set up a 72 point white font
pw.SetColor("white")
dw.SetFillColor(pw)
// Now draw the text
dw.Annotation(25, 65, "Magick")
// Draw the image on to the mw
mw.DrawImage(dw)
// the "gray" parameter must be true to get the effect shown on Anthony's page
mw.ShadeImage(true, 140, 60)
pw.SetColor("yellow")
dw.SetFillColor(pw)
cpw := imagick.NewPixelWand()
defer cpw.Destroy()
cpw.SetColor("gold")
mw.ColorizeImage(pw, cpw)
// and write it
mw.WriteImage("text_bevel.png")
}
开发者ID:rafikk,项目名称:imagick,代码行数:34,代码来源:main.go
示例8: textEffect3
// Text effect 3 - arc font (similar to http://www.imagemagick.org/Usage/fonts/#arc)
func textEffect3() {
imagick.Initialize()
defer imagick.Terminate()
mw := imagick.NewMagickWand()
defer mw.Destroy()
dw := imagick.NewDrawingWand()
defer dw.Destroy()
pw := imagick.NewPixelWand()
defer pw.Destroy()
// Create a 320x100 lightblue canvas
pw.SetColor("lightblue")
mw.NewImage(320, 100, pw)
// Set up a 72 point font
dw.SetFont("Verdana-Bold-Italic")
dw.SetFontSize(72)
// Now draw the text
dw.Annotation(25, 65, "Magick")
// Draw the image on to the mw
mw.DrawImage(dw)
mw.DistortImage(imagick.DISTORTION_ARC, dargs, false)
// Trim the image
mw.TrimImage(0)
// Add the border
pw.SetColor("lightblue")
mw.BorderImage(pw, 10, 10)
// and write it
mw.WriteImage("text_arc.png")
}
开发者ID:rafikk,项目名称:imagick,代码行数:29,代码来源:main.go
示例9: textEffect5And6
// Text effect 5 and 6 - Plain text and then Barrel distortion
func textEffect5And6() {
imagick.Initialize()
defer imagick.Terminate()
// This one uses d_args
mw := imagick.NewMagickWand()
defer mw.Destroy()
dw := imagick.NewDrawingWand()
defer dw.Destroy()
pw := imagick.NewPixelWand()
defer pw.Destroy()
// Create a 320x100 transparent canvas
pw.SetColor("none")
mw.NewImage(320, 100, pw)
// Set up a 72 point font
dw.SetFont("Verdana-Bold-Italic")
dw.SetFontSize(72)
// Now draw the text
dw.Annotation(25, 65, "Magick")
// Draw the image on to the mw
mw.DrawImage(dw)
mw.WriteImage("text_plain.png")
// Trim the image
mw.TrimImage(0)
// Add the border
pw.SetColor("none")
mw.BorderImage(pw, 10, 10)
//mw.SetImageMatte(true)
//mw.SetImageVirtualPixelMethod(TransparentVirtualPixelMethod)
// d_args[0] = 0.1;d_args[1] = -0.25;d_args[2] = -0.25; [3] += .1
// The first value should be positive. If it is negative the image is *really* distorted
d_args[0] = 0.0
d_args[1] = 0.0
d_args[2] = 0.5
// d_args[3] should normally be chosen such the sum of all 4 values is 1
// so that the result is the same size as the original
// You can override the sum with a different value
// If the sum is greater than 1 the resulting image will be smaller than the original
d_args[3] = 1 - (d_args[0] + d_args[1] + d_args[2])
// Make the result image smaller so that it isn't as likely
// to overflow the edges
// d_args[3] += 0.1
// 0.0,0.0,0.5,0.5,0.0,0.0,-0.5,1.9
d_args[3] = 0.5
d_args[4] = 0.0
d_args[5] = 0.0
d_args[6] = -0.5
d_args[7] = 1.9
// DON'T FORGET to set the correct number of arguments here
mw.DistortImage(imagick.DISTORTION_BARREL, d_args, true)
//mw.ResetImagePage("")
// Trim the image again
mw.TrimImage(0)
// Add the border
pw.SetColor("none")
mw.BorderImage(pw, 10, 10)
// and write it
mw.WriteImage("text_barrel.png")
}
开发者ID:rafikk,项目名称:imagick,代码行数:59,代码来源:main.go
示例10: example4
// Example 4
// Create a rotated gradient
// See: http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=12707
// The affine in this one is essentially the same as the one in Example 2 but
// this example has a different use for the result
func example4() {
imagick.Initialize()
defer imagick.Terminate()
t1 := make([]float64, 6)
r := make([]float64, 6)
t2 := make([]float64, 6)
temp := make([]float64, 6)
result := make([]float64, 6)
// Dimensions of the final rectangle
w := uint(600)
h := uint(100)
// angle of clockwise rotation
theta := 15.0 // degrees
// Convert theta to radians
rad_theta := DegreesToRadians(theta)
// Compute the dimensions of the rectangular gradient
gw := (uint)(float64(w)*math.Cos(rad_theta) + float64(h)*math.Sin(rad_theta) + 0.5)
gh := (uint)(float64(w)*math.Sin(rad_theta) + float64(h)*math.Cos(rad_theta) + 0.5)
// Don't let the rotation make the gradient rectangle any smaller
// than the required output
if gw < w {
gw = w
}
if gh < h {
gh = h
}
mw := imagick.NewMagickWand()
defer mw.Destroy()
mw.SetSize(gw, gh)
mw.ReadImage("gradient:white-black")
// Initialize the required affines
// translate centre of gradient to origin
set_translate_affine(t1, float64(-gw)/2.0, float64(-gh)/2.0)
// rotate clockwise by theta degrees
set_rotate_affine(r, theta)
// translate back again
set_translate_affine(t2, float64(gw)/2.0, float64(gh)/2.0)
// Now multiply the affine sequences
// temp = t1*r
affine_multiply(temp, t1, r)
// result = temp*t2
affine_multiply(result, temp, t2)
mw.DistortImage(imagick.DISTORTION_AFFINE_PROJECTION, result, false)
// Get the size of the distorted image and crop out the middle
nw := mw.GetImageWidth()
nh := mw.GetImageHeight()
mw.CropImage(w, h, int((nw-w)/2), int((nh-h)/2))
mw.WriteImage("rotgrad_2.png")
}
开发者ID:rafikk,项目名称:imagick,代码行数:61,代码来源:main.go
示例11: NewImageFromBuffer
func NewImageFromBuffer(buffer io.Reader) (image *Image, err error) {
bytes, err := ioutil.ReadAll(buffer)
if err != nil {
return nil, err
}
image = &Image{Wand: imagick.NewMagickWand()}
err = image.Wand.ReadImageBlob(bytes)
if err != nil {
return nil, err
}
return image, nil
}
开发者ID:Wiredcraft,项目名称:halfshell,代码行数:14,代码来源:image.go
示例12: setTilePattern
// Given a pattern name (which MUST have a leading #) and a pattern file,
// set up a pattern URL for later reference in the specified drawing wand
// Currently only used in Text Effect 2
func setTilePattern(dw *imagick.DrawingWand, pattern_name, pattern_file string) {
tw := imagick.NewMagickWand()
defer tw.Destroy()
tw.ReadImage(pattern_file)
// Read the tile's width and height
w := tw.GetImageWidth()
h := tw.GetImageHeight()
dw.PushPattern(pattern_name[1:], 0, 0, float64(w), float64(h))
dw.Composite(imagick.COMPOSITE_OP_SRC_OVER, 0, 0, 0, 0, tw)
dw.PopPattern()
dw.SetFillPatternURL(pattern_name)
}
开发者ID:rafikk,项目名称:imagick,代码行数:17,代码来源:main.go
示例13: example3
// Example 3
// Reflect the image about a line passing through the origin.
// If the line makes an angle of D degrees with the horizontal
// then this can be done by rotating the image by -D degrees so
// that the line is now (in effect) the x axis, reflect the image
// across the x axis, and then rotate everything back again.
// In this example, rather than just picking an arbitrary angle,
// let's say that we want the "logo:" image to be reflected across
// it's own major diagonal. Although we know the logo: image is
// 640x480 let's also generalize the code slightly so that it
// will still work if the name of the input image is changed.
// If the image has a width "w" and height "h", then the angle between
// the x-axis and the major diagonal is atan(h/w) (NOTE that this
// result is in RADIANS!)
// For this example I will also retain the original dimensions of the
// image so that anything that is reflected outside the borders of the
// input image is lost
func example3() {
imagick.Initialize()
defer imagick.Terminate()
r1 := make([]float64, 6)
reflect := make([]float64, 6)
r2 := make([]float64, 6)
temp := make([]float64, 6)
result := make([]float64, 6)
var angle_degrees float64
mw := imagick.NewMagickWand()
defer mw.Destroy()
mw.ReadImage("logo:")
w := mw.GetImageWidth()
h := mw.GetImageHeight()
// Just convert the radians to degrees. This way I don't have
// to write a function which sets up an affine rotation for an
// argument specified in radians rather than degrees.
// You can always change this.
angle_degrees = RadiansToDegrees(math.Atan(float64(h) / float64(w)))
// Initialize the required affines
// Rotate diagonal to the x axis
set_rotate_affine(r1, -angle_degrees)
// Reflection affine (about x-axis)
// In this case there isn't a specific function to set the
// affine array (like there is for rotation and scaling)
// so use the function which sets an arbitrary affine
set_affine(reflect, 1, 0, 0, -1, 0, 0)
// rotate image back again
set_rotate_affine(r2, angle_degrees)
// temp = r1*reflect
affine_multiply(temp, r1, reflect)
// result = temp*r2
affine_multiply(result, temp, r2)
mw.DistortImage(imagick.DISTORTION_AFFINE_PROJECTION, result, false)
mw.WriteImage("logo_affine_3.jpg")
}
开发者ID:rafikk,项目名称:imagick,代码行数:59,代码来源:main.go
示例14: usePixelIterator
func usePixelIterator() {
imagick.Initialize()
defer imagick.Terminate()
/* Create a wand */
mw := imagick.NewMagickWand()
defer mw.Destroy()
/* Read the input image */
mw.ReadImage("logo:")
// Get a one-pixel region at coordinate 200,100
iterator := mw.NewPixelRegionIterator(200, 100, 1, 1)
defer iterator.Destroy()
pixels := iterator.GetNextIteratorRow()
// Modify the pixel
pixels[0].SetColor("red")
// then sync it back into the wand
iterator.SyncIterator()
mw.WriteImage("logo_pixel_iterator.gif")
}
开发者ID:rafikk,项目名称:imagick,代码行数:20,代码来源:main.go
示例15: useDraw
func useDraw() {
imagick.Initialize()
defer imagick.Terminate()
/* Create a wand */
mw := imagick.NewMagickWand()
defer mw.Destroy()
/* Read the input image */
mw.ReadImage("logo:")
fill := imagick.NewPixelWand()
defer fill.Destroy()
dw := imagick.NewDrawingWand()
defer dw.Destroy()
// Set the fill to "red" or you can do the same thing with this:
fill.SetColor("red")
dw.SetFillColor(fill)
// Uses the current Fill as the colour of the point at 200,100
dw.Point(200, 100)
mw.DrawImage(dw)
/* write it */
mw.WriteImage("logo_pixel_drawingwand.gif")
}
开发者ID:rafikk,项目名称:imagick,代码行数:22,代码来源:main.go
示例16: textEffect8
// Text effect 8 - Shepard's distortion
func textEffect8() {
imagick.Initialize()
defer imagick.Terminate()
// This one uses d_args[0]
mw := imagick.NewMagickWand()
defer mw.Destroy()
dw := imagick.NewDrawingWand()
defer dw.Destroy()
pw := imagick.NewPixelWand()
defer pw.Destroy()
// Create a 320x200 transparent canvas
pw.SetColor("none")
mw.NewImage(640, 480, pw)
// Set up a 72 point font
dw.SetFont("Verdana-Bold-Italic")
dw.SetFontSize(72)
// Now draw the text
dw.Annotation(50, 240, "Magick Rocks")
// Draw the image on to the mw
mw.DrawImage(dw)
d_args[0] = 150.0
d_args[1] = 190.0
d_args[2] = 100.0
d_args[3] = 290.0
d_args[4] = 500.0
d_args[5] = 200.0
d_args[6] = 430.0
d_args[7] = 130.0
// DON'T FORGET to set the correct number of arguments here
mw.DistortImage(imagick.DISTORTION_SHEPARDS, d_args, true)
// Trim the image
mw.TrimImage(0)
// Add the border
pw.SetColor("none")
mw.BorderImage(pw, 10, 10)
// and write it
mw.WriteImage("text_shepards.png")
}
开发者ID:rafikk,项目名称:imagick,代码行数:39,代码来源:main.go
示例17: example1
// Example 1.
// Rotate logo: by 90 degrees (about the origin), scale by 50 percent and
// then move the image 240 in the x direction
func example1() {
imagick.Initialize()
defer imagick.Terminate()
s := make([]float64, 6)
r := make([]float64, 6)
t := make([]float64, 6)
temp := make([]float64, 6)
result := make([]float64, 6)
mw := imagick.NewMagickWand()
defer mw.Destroy()
mw.ReadImage("logo:")
// Set up the affine matrices
// rotate 90 degrees clockwise
set_rotate_affine(r, 90)
// scale by .5 in x and y
set_scale_affine(s, 0.5, 0.5)
// translate to (240,0)
set_translate_affine(t, 240, 0)
// now multiply them - note the order in
// which they are specified - in particular beware that
// temp = r*s is NOT necessarily the same as temp = s*r
//first do the rotation and scaling
// temp = r*s
affine_multiply(temp, r, s)
// now the translation
// result = temp*t
affine_multiply(result, temp, t)
// and then apply the result to the image
mw.DistortImage(imagick.DISTORTION_AFFINE_PROJECTION, result, false)
mw.WriteImage("logo_affine_1.jpg")
}
开发者ID:rafikk,项目名称:imagick,代码行数:40,代码来源:main.go
注:本文中的github.com/rafikk/imagick/imagick.NewMagickWand函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论