本文整理匯總了Golang中github.com/gographics/imagick/imagick.NewMagickWand函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewMagickWand函數的具體用法?Golang NewMagickWand怎麽用?Golang NewMagickWand使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewMagickWand函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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")
}
示例2: GenerateImage
func (this *JmaImageGenerator) GenerateImage(date string, digest string) string {
mapImage := image.ReadImageFromAsset("data/jma_map.png")
defer mapImage.Destroy()
maskImage := image.ReadImageFromAsset("data/jma_mask.png")
defer maskImage.Destroy()
manucipalityImage := image.ReadImageFromAsset("data/jma_manucipality.png")
defer manucipalityImage.Destroy()
ihrImage := image.ReadImageFromAsset("data/ihr.png")
defer ihrImage.Destroy()
rainImage := imagick.NewMagickWand()
defer rainImage.Destroy()
for w := MIN_WIDTH; w <= MAX_WIDTH; w++ {
tmpImage := imagick.NewMagickWand()
defer tmpImage.Destroy()
for h := MIN_HEIGHT; h <= MAX_HEIGHT; h++ {
tmp := image.GetImageFromUrl("http://www.jma.go.jp/jp/highresorad/highresorad_tile/HRKSNC/" + date + "/" + date + "/zoom6/" + strconv.Itoa(w) + "_" + strconv.Itoa(h) + ".png")
defer tmp.Destroy()
tmpImage.AddImage(tmp)
tmpImage.SetLastIterator()
}
tmpImage.SetFirstIterator()
tmpImage = tmpImage.AppendImages(true)
rainImage.AddImage(tmpImage)
rainImage.SetLastIterator()
}
rainImage.SetFirstIterator()
rainImage = rainImage.AppendImages(false)
rainImage.AdaptiveResizeImage(2048, 2048)
err := mapImage.CompositeImage(rainImage, imagick.COMPOSITE_OP_OVER, 0, 0)
if err != nil {
log.Println(err)
}
err = mapImage.CompositeImage(maskImage, imagick.COMPOSITE_OP_OVER, 0, 0)
if err != nil {
log.Println(err)
}
err = mapImage.CompositeImage(manucipalityImage, imagick.COMPOSITE_OP_OVER, 0, 0)
if err != nil {
log.Println(err)
}
err = mapImage.CropImage(1000, 500, 580, 750)
if err != nil {
log.Println(err)
}
err = mapImage.CompositeImage(ihrImage, imagick.COMPOSITE_OP_OVER, 750, 300)
if err != nil {
log.Println(err)
}
url, err := image.Upload(digest+".png", mapImage.GetImageBlob())
if err != nil {
fmt.Println(err)
}
return url
}
示例3: main
func main() {
imagick.Initialize()
defer imagick.Terminate()
mw := imagick.NewMagickWand()
defer mw.Destroy()
aw := imagick.NewMagickWand()
defer aw.Destroy()
// Read the first input image
if err := mw.ReadImage("bunny_grass.gif"); err != nil {
panic(err)
}
// We need a separate wand to do this bit in parentheses
if err := aw.ReadImage("bunny_anim.gif"); err != nil {
panic(err)
}
aw.ResetImagePage("0x0+5+15!")
// Now we have to add the images in the aw wand on to the end
// of the mw wand.
mw.AddImage(aw)
// We can now destroy the aw wand so that it can be used
// for the next operation
aw.Destroy()
// -coalesce
aw = mw.CoalesceImages()
// do "-delete 0" by copying the images from the "aw" wand to
// the "mw" wand but omit the first one
// free up the mw wand and recreate it for this step
mw.Destroy()
mw = imagick.NewMagickWand()
for i := 1; i < int(aw.GetNumberImages()); i++ {
aw.SetIteratorIndex(i)
tw := aw.GetImage()
mw.AddImage(tw)
tw.Destroy()
}
mw.ResetIterator()
aw.Destroy()
// -deconstruct
// Anthony says that MagickDeconstructImages is equivalent
// to MagickCompareImagesLayers so we'll use that
aw = mw.CompareImageLayers(imagick.IMAGE_LAYER_COMPARE_ANY)
// -loop 0
aw.SetOption("loop", "0")
// write the images into one file
if err := aw.WriteImages("bunny_bgnd.gif", true); err != nil {
panic(err)
}
}
示例4: placeit
// Actually placed screenshot onto background image
func placeit(image_id string, xml_data Result, image []byte) string {
imagick.Initialize()
defer imagick.Terminate()
width, _ := strconv.Atoi(xml_data.Device.Resolution.Width)
height, _ := strconv.Atoi(xml_data.Device.Resolution.Height)
x_positions := make([]int, 4)
x_positions[0], _ = strconv.Atoi(xml_data.Device.Placement.Top_left_x)
x_positions[1], _ = strconv.Atoi(xml_data.Device.Placement.Top_right_x)
x_positions[2], _ = strconv.Atoi(xml_data.Device.Placement.Bottom_right_x)
x_positions[3], _ = strconv.Atoi(xml_data.Device.Placement.Bottom_left_x)
y_positions := make([]int, 4)
y_positions[0], _ = strconv.Atoi(xml_data.Device.Placement.Top_left_y)
y_positions[1], _ = strconv.Atoi(xml_data.Device.Placement.Top_right_y)
y_positions[2], _ = strconv.Atoi(xml_data.Device.Placement.Bottom_right_y)
y_positions[3], _ = strconv.Atoi(xml_data.Device.Placement.Bottom_left_y)
base_x := x_positions[0]
base_y := y_positions[0]
result := []float64{0, 0,
float64(x_positions[0] - base_x), float64(y_positions[0] - base_y),
float64(width), 0,
float64(x_positions[1] - base_x), float64(y_positions[1] - base_y),
float64(width), float64(height),
float64(x_positions[2] - base_x), float64(y_positions[2] - base_y),
0, float64(height),
float64(x_positions[3] - base_x), float64(y_positions[3] - base_y)}
mw := imagick.NewMagickWand()
defer mw.Destroy()
back_mw := imagick.NewMagickWand()
defer back_mw.Destroy()
mw.ReadImageBlob(image)
back_mw.ReadImage("src/github.com/JustinJudd/go_snappshot/public/images/backgrounds/" + image_id + ".jpg")
mw.SetImageVirtualPixelMethod(imagick.VIRTUAL_PIXEL_TRANSPARENT)
mw.DistortImage(imagick.DISTORTION_PERSPECTIVE, result, true)
sort.IntSlice.Sort(x_positions)
sort.IntSlice.Sort(y_positions)
back_mw.CompositeImage(mw, imagick.COMPOSITE_OP_OVER, x_positions[0], y_positions[0])
placed_id := strconv.Itoa(int(time.Now().UnixNano()))
back_mw.WriteImage(getGeneratedPath(placed_id))
return placed_id
}
示例5: 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")
}
示例6: 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")
}
示例7: GetImageInfo
func (ng Engine) GetImageInfo(b []byte, srcFormat ...string) (*imgry.ImageInfo, error) {
if len(b) == 0 {
return nil, imgry.ErrInvalidImageData
}
mw := imagick.NewMagickWand()
defer mw.Destroy()
if !mw.IsVerified() {
return nil, ErrEngineFailure
}
err := mw.PingImageBlob(b)
if err != nil {
return nil, imgry.ErrInvalidImageData
}
w, h := int(mw.GetImageWidth()), int(mw.GetImageHeight())
ar := float64(int(float64(w)/float64(h)*10000)) / 10000
format := strings.ToLower(mw.GetImageFormat())
if format == "jpeg" {
format = "jpg"
}
imfo := &imgry.ImageInfo{
Format: format, Width: w, Height: h,
AspectRatio: ar, ContentLength: len(b),
}
return imfo, nil
}
示例8: LoadBlob
func (ng Engine) LoadBlob(b []byte, srcFormat ...string) (imgry.Image, error) {
if len(b) == 0 {
return nil, imgry.ErrInvalidImageData
}
mw := imagick.NewMagickWand()
if !mw.IsVerified() {
return nil, ErrEngineFailure
}
// Offer a hint to the decoder of the file format
if len(srcFormat) > 0 {
f := srcFormat[0]
if f != "" {
mw.SetFormat(f)
}
}
err := mw.ReadImageBlob(b)
if err != nil {
mw.Destroy()
return nil, imgry.ErrInvalidImageData
}
// TODO: perhaps we pass the engine instance like Image{engine: i}
im := &Image{mw: mw, data: b}
if err := im.sync(); err != nil {
mw.Destroy()
return nil, err
}
return im, nil
}
示例9: 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")
}
示例10: 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()
}
示例11: 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)
}
示例12: 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")
}
示例13: imageFromUrl
func imageFromUrl(w http.ResponseWriter, r *http.Request) (*imagick.MagickWand, error) {
queryUrl := r.URL.Query().Get("url")
url, _ := url.QueryUnescape(queryUrl)
resp, err := http.Get(url)
if err != nil {
return nil, err
}
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
http.Error(w, "Error retrieving url", 500)
return nil, err
}
wand := imagick.NewMagickWand()
err = wand.ReadImageBlob(data)
if err != nil {
http.Error(w, "Error retrieving url", 500)
return nil, err
}
if err = wand.SetImageFormat("JPG"); err != nil {
http.Error(w, "Error retrieving url", 500)
return nil, err
}
wand.AutoLevelImage()
return wand, nil
}
示例14: 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")
}
示例15: glitchImage
func glitchImage(wand *imagick.MagickWand, q url.Values) ([]byte, error) {
data := wand.GetImage().GetImageBlob()
jpgHeaderLength := getJpegHeaderSize(data)
maxIndex := len(data) - jpgHeaderLength - 4
params := getParams(q)
length := int(params["iterations"])
for i := 0; i < length; i++ {
pxMin := math.Floor(float64(maxIndex) / params["iterations"] * float64(i))
pxMax := math.Floor(float64(maxIndex) / params["iterations"] * float64((i + 1)))
delta := pxMax - pxMin
pxI := math.Floor(pxMin + delta*params["seed"])
if int(pxI) > maxIndex {
pxI = float64(maxIndex)
}
index := math.Floor(float64(jpgHeaderLength) + pxI)
data[int(index)] = byte(math.Floor(params["amount"] * float64(256)))
}
wand2 := imagick.NewMagickWand()
if err := wand2.ReadImageBlob(data); err != nil {
return nil, err
}
if err := wand2.SetImageFormat("PNG"); err != nil {
return nil, err
}
return wand2.GetImage().GetImageBlob(), nil
}