本文整理匯總了Golang中github.com/gographics/imagick/imagick.Initialize函數的典型用法代碼示例。如果您正苦於以下問題:Golang Initialize函數的具體用法?Golang Initialize怎麽用?Golang Initialize使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Initialize函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: main
func main() {
// Note that the colours are stored as separate *normalized* RGB components
arglist := []float64{
0, 0,
// RGB black
0, 0, 0,
// The y coordinate is filled in later
0, -1,
// RGB white
1, 1, 1,
}
// arguments for MagickFunctionImage
funclist := []float64{4, -4, 1}
imagick.Initialize()
defer imagick.Terminate()
mw := imagick.NewMagickWand()
defer mw.Destroy()
mw.ReadImage("beijing_md.jpg")
// fill in the Y coordinate now that we can get the image dimensions
arglist[6] = float64(mw.GetImageHeight() - 1)
mw.SigmoidalContrastImage(true, 15, imagick.QUANTUM_RANGE*30/100)
cw := mw.Clone()
defer cw.Destroy()
cw.SparseColorImage(imagick.CHANNELS_RGB, imagick.INTERPOLATE_BARYCENTRIC_COLOR, arglist)
// Do the polynomial function
cw.FunctionImage(imagick.FUNCTION_POLYNOMIAL, funclist)
// -set option:compose:args 15
if err := cw.SetImageArtifact("compose:args", "15"); err != nil {
panic(err)
}
mw.CompositeImage(cw, imagick.COMPOSITE_OP_BLUR, 0, 0)
mw.WriteImage("beijing_model.jpg")
}
示例2: main
func main() {
flag.Parse()
imagick.Initialize()
defer imagick.Terminate()
mw := imagick.NewMagickWand()
defer mw.Destroy()
var err error
if flag.NArg() < 1 {
fmt.Println("Usage: imagick_profiles <imgfile> [<proftype>]\n")
os.Exit(1)
}
basename := flag.Arg(0)
err = mw.ReadImage(basename)
if err != nil {
fmt.Println("ReadImage Error:", err)
os.Exit(1)
}
if flag.NArg() == 1 {
profs := mw.GetImageProfiles("*")
fmt.Println(profs)
} else {
proftype := flag.Arg(1)
prof := mw.GetImageProfile(proftype)
fmt.Print(prof)
}
}
示例3: main
func main() {
var err error
imagick.Initialize()
defer imagick.Terminate()
mw := imagick.NewMagickWand()
defer mw.Destroy()
bg := imagick.NewPixelWand()
defer bg.Destroy()
fg := imagick.NewPixelWand()
defer fg.Destroy()
err = mw.ReadImage("http://www.imagemagick.org/Usage/images/cyclops_sm.gif")
if err != nil {
panic(err)
}
bg.SetColor("white")
mw.BorderImage(bg, 1, 1)
mw.SetImageAlphaChannel(imagick.ALPHA_CHANNEL_SET)
fg.SetColor("none")
channel := imagick.CHANNELS_RGB | imagick.CHANNEL_ALPHA
// Floodfill the "background" colour with the "foreground" colour
// starting at coordinate 0,0 using a fuzz of 20
mw.FloodfillPaintImage(channel, fg, 20, bg, 0, 0, false)
mw.ShaveImage(1, 1)
mw.DisplayImage(os.Getenv("DISPLAY"))
if err != nil {
panic(err)
}
}
示例4: 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")
}
示例5: 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")
}
示例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")
}
示例7: 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")
}
示例8: main
func main() {
imagick.Initialize()
defer imagick.Terminate()
// Start chunking workers
imagesChan := make(chan []byte)
for i := 0; i < chunkersCnt; i++ {
go scheduleChunking(imagesChan)
}
// Start token store cleaner
go tokenStoreCleaner(time.Tick(tokenCleanup))
// Serve Assets
http.Handle("/css/", http.FileServer(http.Dir("./assets")))
http.Handle("/js/", http.FileServer(http.Dir("./assets")))
http.Handle("/fonts/", http.FileServer(http.Dir("./assets")))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
switch {
case r.Method == "POST" && r.URL.Path == "/":
handlePost(imagesChan, w, r)
case r.Method == "GET" && r.URL.Path == "/":
handleGetIndex(w, r)
default:
log.Println("404: ", r.URL.Path)
http.NotFound(w, r)
}
})
log.Println("Server started")
log.Fatal(http.ListenAndServe(":8080", nil))
}
示例9: TestResize
func TestResize(t *testing.T) {
imagick.Initialize()
defer imagick.Terminate()
tests := []*ResizeCase{
{"fixture/circle.png", 30, 150},
}
if err := os.Mkdir("test-out", os.ModeDir|os.ModePerm); os.IsNotExist(err) {
t.Fatal(err)
}
for i, x := range tests {
before, err := ioutil.ReadFile(x.filename)
if err != nil {
t.Fatal(err)
}
after, err := Resize(before, x.w, x.h)
if err != nil {
t.Fatal(err)
}
filename := fmt.Sprintf("test-out/resize-%dx%d-%d%s", x.w, x.h, i, filepath.Ext(x.filename))
err = ioutil.WriteFile(filename, after, os.ModePerm)
if err != nil {
t.Fatal(err)
}
}
}
示例10: 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")
}
示例11: 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")
}
示例12: Draw
func Draw(text string, name string) {
imagick.Initialize()
defer imagick.Terminate()
// Current coordinates of text
var dx float64 = 20
mw := imagick.NewMagickWand()
dw := imagick.NewDrawingWand()
defer mw.Destroy()
defer dw.Destroy()
// Set the size of the image
mw.SetSize(285, 50)
mw.ReadImage("../assets/images/bg.gif")
// Start near the left edge
dw.SetFontSize(40)
// Note that we must free up the fontmetric array once we're done with it
list := strings.Split(text, " ")
for _, item := range list {
writeWord(mw, dw, &dx, item)
}
mw.DrawImage(dw)
// Now write the magickwand image
mw.WriteImage(name)
}
示例13: getTextImage
func getTextImage(text string, size int) []byte {
imagick.Initialize()
defer imagick.Terminate()
mw := imagick.NewMagickWand()
defer mw.Destroy()
dw := imagick.NewDrawingWand()
defer dw.Destroy()
pw := imagick.NewPixelWand()
defer pw.Destroy()
l := len(text)
w := size * 3 * (l + 6)
h := size * 2
pw.SetColor("none")
mw.NewImage(uint(w), uint(h), pw)
pw.SetColor("white")
dw.SetFillColor(pw)
dw.SetFont("/usr/share/fonts/default/TrueType/msyh.ttf")
dw.SetFontSize(float64(size))
dw.Annotation(0, float64(size), "ctrip © "+text)
mw.DrawImage(dw)
mw.TrimImage(0)
mw.ResetImagePage("")
cw := mw.Clone()
pw.SetColor("black")
mw.SetImageBackgroundColor(pw)
mw.ShadowImage(100, 1, 0, 0)
mw.CompositeImage(cw, imagick.COMPOSITE_OP_OVER, 1, 1)
cw.Destroy()
mw.SetImageFormat("PNG")
return mw.GetImageBlob()
}
示例14: Screenshot
func (c Snappshot) Screenshot(res string) revel.Result {
s := strings.Split(res, "x")
width, _ := strconv.Atoi(s[0])
height, _ := strconv.Atoi(s[1])
imagick.Initialize()
defer imagick.Terminate()
mw := imagick.NewMagickWand()
defer mw.Destroy()
dw := imagick.NewDrawingWand()
defer dw.Destroy()
cw := imagick.NewPixelWand()
cw2 := imagick.NewPixelWand()
cw.SetColor("darkgray")
cw2.SetColor("white")
mw.NewImage(uint(width), uint(height), cw)
dw.SetTextAlignment(imagick.ALIGN_CENTER)
dw.SetFillColor(cw2)
dw.SetFontSize(150)
cw2.SetColor("black")
dw.SetStrokeColor(cw2)
dw.Annotation(float64(width)/2, float64(height)/2, res)
mw.DrawImage(dw)
mw.SetImageFormat("jpg")
output := mw.GetImageBlob()
return JPGImage(output)
}
示例15: ExtractThumbnail
// Extracts thumbnail
func (c *Convertor) ExtractThumbnail(file string, info os.FileInfo) {
c.CurrFile += 1
cover, err := c.GetCoverImage(file, info)
if err != nil {
fmt.Fprintf(os.Stderr, "Error GetCoverImage: %v\n", err.Error())
return
}
if err != nil {
fmt.Fprintf(os.Stderr, "Error Thumbnail: %v\n", err.Error())
return
}
if c.Opts.Width > 0 || c.Opts.Height > 0 {
if c.Opts.Fit {
cover = imaging.Fit(cover, c.Opts.Width, c.Opts.Height, filters[c.Opts.Filter])
} else {
cover = imaging.Resize(cover, c.Opts.Width, c.Opts.Height, filters[c.Opts.Filter])
}
} else {
cover = imaging.Resize(cover, 256, 0, filters[c.Opts.Filter])
}
imagick.Initialize()
mw := imagick.NewMagickWand()
defer mw.Destroy()
b := new(bytes.Buffer)
png.Encode(b, cover)
err = mw.ReadImageBlob(b.Bytes())
if err != nil {
fmt.Fprintf(os.Stderr, "Error ReadImageBlob: %v\n", err.Error())
}
var fileuri string
var filename string
if c.Opts.Outfile == "" {
fileuri = "file://" + file
filename = filepath.Join(c.Opts.Outdir, fmt.Sprintf("%x.png", md5.Sum([]byte(fileuri))))
} else {
abs, _ := filepath.Abs(c.Opts.Outfile)
fileuri = "file://" + abs
filename = abs
}
mw.SetImageFormat("PNG")
mw.SetImageProperty("Software", "CBconvert")
mw.SetImageProperty("Description", "Thumbnail of "+fileuri)
mw.SetImageProperty("Thumb::URI", fileuri)
mw.SetImageProperty("Thumb::MTime", strconv.FormatInt(info.ModTime().Unix(), 10))
mw.SetImageProperty("Thumb::Size", strconv.FormatInt(info.Size(), 10))
mw.SetImageProperty("Thumb::Mimetype", mime.TypeByExtension(filepath.Ext(file)))
mw.WriteImage(filename)
}