本文整理匯總了Golang中github.com/gographics/imagick/imagick.MagickWand類的典型用法代碼示例。如果您正苦於以下問題:Golang MagickWand類的具體用法?Golang MagickWand怎麽用?Golang MagickWand使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了MagickWand類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: draw_setfont
// 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
}
}
示例2: 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
}
示例3: createChunk
func createChunk(mask, image *imagick.MagickWand, x, y int) error {
if err := mask.CompositeImage(image, imagick.COMPOSITE_OP_SRC_IN, -x, -y); err != nil {
return err
// fmt.Sprintf("Chunking for (%d;%d) failed: %v", x, y, err)
}
if err := mask.WriteImage("tmp/" + strconv.Itoa(x) + "_" + strconv.Itoa(y) + ".png"); err != nil {
return err
// fmt.Sprintf("Saving chunk for (%d;%d) failed: %v", x, y, err)
}
return nil
}
示例4: calcDnR
func calcDnR(image *imagick.MagickWand) (d uint, r float64) {
width := image.GetImageWidth()
height := image.GetImageHeight()
if height > width {
d = width / minChunksPerSide
} else {
d = height / minChunksPerSide
}
r = float64(d) / 2
return
}
示例5: Fix
func (orientation *Orientation) Fix(wand *imagick.MagickWand) error {
if orientation.fn == nil {
return nil
}
if err := orientation.fn(wand); err != nil {
return err
}
if err := wand.SetImageOrientation(imagick.ORIENTATION_TOP_LEFT); err != nil {
return err
}
*orientation = Orientation{swapXY: false, flipX: false, flipY: false, fn: nil}
return nil
}
示例6: resize
func (i *Image) resize(wand *imagick.MagickWand, w, h uint) {
ow := wand.GetImageWidth()
oh := wand.GetImageHeight()
if (float64(ow) / float64(oh)) < (float64(w) / float64(h)) {
h = oh * w / ow
} else {
w = ow * h / oh
}
wand.SetImageInterpolateMethod(imagick.INTERPOLATE_PIXEL_BICUBIC)
wand.ResizeImage(w, h, imagick.FILTER_LANCZOS2_SHARP, 1)
}
示例7: crop
func crop(mw *imagick.MagickWand, x, y int, cols, rows uint) error {
var result error
result = nil
imCols := mw.GetImageWidth()
imRows := mw.GetImageHeight()
if x < 0 {
x = 0
}
if y < 0 {
y = 0
}
if uint(x) >= imCols || uint(y) >= imRows {
result = fmt.Errorf("x, y more than image cols, rows")
return result
}
if cols == 0 || imCols < uint(x)+cols {
cols = imCols - uint(x)
}
if rows == 0 || imRows < uint(y)+rows {
rows = imRows - uint(y)
}
fmt.Print(fmt.Sprintf("wi_crop(im, %d, %d, %d, %d)\n", x, y, cols, rows))
result = mw.CropImage(cols, rows, x, y)
return result
}
示例8: resize
func resize(mw *imagick.MagickWand, geo btcdn.GeoBox) (err error) {
var height uint
width := geo.Width()
baseWidth := int(mw.GetImageWidth())
if width > baseWidth {
width = baseWidth
}
if geo.Mode() == "!" {
height = uint(geo.Height())
} else {
ratio := heightToWidthRatio(mw)
height = uint((float64)(width) * ratio)
}
err = mw.ResizeImage(uint(width), height, imagick.FILTER_LANCZOS, 1)
if err != nil {
return
}
return
}
示例9: shrinkImage
// Shrink an image so that its longest dimension is no longer than maxSize
func shrinkImage(wand *imagick.MagickWand, maxSize int) (w, h uint) {
w, h = getDimensions(wand)
shrinkBy := 1
if w >= h {
shrinkBy = int(w) / maxSize
} else {
shrinkBy = int(h) / maxSize
}
wand.AdaptiveResizeImage(
uint(int(w)/shrinkBy),
uint(int(h)/shrinkBy),
)
// Sharpen the image to bring back some of the color lost in the shrinking
wand.AdaptiveSharpenImage(0, AdaptiveSharpenVal)
w, h = getDimensions(wand)
return
}
示例10: draw_metrics
// 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
}
}
示例11: drawMetrics
func drawMetrics(mw *imagick.MagickWand, dw *imagick.DrawingWand, dx *float64, text string) {
rotation := float64(random(-30, 30))
mw.AnnotateImage(dw, *dx, 35, rotation, text)
mw.DrawImage(dw)
// get the font metrics
fm := mw.QueryFontMetrics(dw, text)
if fm != nil {
// Adjust the new x coordinate
*dx += fm.TextWidth + 2
}
}
示例12: crop
func crop(mw *imagick.MagickWand, geo btcdn.GeoBox) (err error) {
offsetX, offsetY, err := calculateGravityOffsets(int(mw.GetImageWidth()), int(mw.GetImageHeight()), geo)
if err != nil {
return
}
err = mw.CropImage(uint(geo.Width()), uint(geo.Height()), offsetX, offsetY)
if err != nil {
return
}
return
}
示例13: speedLine
func speedLine(mw *imagick.MagickWand, aw *imagick.MagickWand) error {
cols, rows := mw.GetImageHeight(), mw.GetImageWidth()
dw := imagick.NewDrawingWand()
defer dw.Destroy()
cw := imagick.NewPixelWand()
cw.SetColor(*color)
dw.SetFillColor(cw)
center := []float64{float64(rows) / 2.0, float64(cols) / 2.0}
const radiusCenter float64 = 0.75
const step float64 = 0.02
const bold float64 = 1.0
var theeta float64
for theeta < math.Pi*2 {
stepNoise := rand.Float64() + 0.5
theeta += step * stepNoise
radiusCenterNoise := rand.Float64()*0.3 + 1.0
boldNoise := rand.Float64() + 0.7 + 0.3
point0 := imagick.PointInfo{
X: math.Sin(theeta)*center[0]*radiusCenter*radiusCenterNoise + center[0],
Y: math.Cos(theeta)*center[1]*radiusCenter*radiusCenterNoise + center[1],
}
point1 := imagick.PointInfo{
X: math.Sin(theeta)*center[0]*2 + center[0],
Y: math.Cos(theeta)*center[1]*2 + center[1],
}
point2 := imagick.PointInfo{
X: math.Sin(theeta+step*bold*boldNoise)*center[0]*2 + center[0],
Y: math.Cos(theeta+step*bold*boldNoise)*center[1]*2 + center[1],
}
dw.Polygon([]imagick.PointInfo{point0, point1, point2})
}
if err := aw.DrawImage(dw); err != nil {
return err
}
return nil
}
示例14: make_tile
// 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()
}
示例15: sizeFrames
func (i *Image) sizeFrames(sz *imgry.Sizing) error {
var canvas *imagick.MagickWand
var bg *imagick.PixelWand
// Shortcut if there is nothing to size
if sz.Size.Equal(imgry.ZeroRect) && sz.CropBox.Equal(imgry.ZeroFloatingRect) {
return nil
}
coalesceAndDeconstruct := !sz.Flatten && i.mw.GetNumberImages() > 1
if coalesceAndDeconstruct {
i.mw = i.mw.CoalesceImages()
}
if sz.Canvas != nil {
// If the user requested a canvas.
canvas = imagick.NewMagickWand()
bg = imagick.NewPixelWand()
bg.SetColor("transparent")
defer func() {
bg.Destroy()
if canvas != nil && canvas != i.mw {
canvas.Destroy()
}
}()
}
i.mw.SetFirstIterator()
for n := true; n; n = i.mw.NextImage() {
pw, ph := int(i.mw.GetImageWidth()), int(i.mw.GetImageHeight())
srcSize := imgry.NewRect(pw, ph)
// Initial crop of the source image
cropBox, cropOrigin, err := sz.CalcCropBox(srcSize)
if err != nil {
return err
}
if cropBox != nil && cropOrigin != nil && !cropBox.Equal(imgry.ZeroRect) {
err := i.mw.CropImage(uint(cropBox.Width), uint(cropBox.Height), cropOrigin.X, cropOrigin.Y)
if err != nil {
return err
}
srcSize = cropBox
i.mw.ResetImagePage("")
}
// Resize the image
resizeRect, cropBox, cropOrigin := sz.CalcResizeRect(srcSize)
if resizeRect != nil && !resizeRect.Equal(imgry.ZeroRect) {
err := i.mw.ResizeImage(uint(resizeRect.Width), uint(resizeRect.Height), imagick.FILTER_LANCZOS, 1.0)
if err != nil {
return err
}
i.mw.ResetImagePage("")
}
// Perform any final crops from an operation
if cropBox != nil && cropOrigin != nil && !cropBox.Equal(imgry.ZeroRect) {
err := i.mw.CropImage(uint(cropBox.Width), uint(cropBox.Height), cropOrigin.X, cropOrigin.Y)
if err != nil {
return err
}
i.mw.ResetImagePage("")
}
// If we have a canvas we put the image at its center.
if canvas != nil {
canvas.NewImage(uint(sz.Canvas.Width), uint(sz.Canvas.Height), bg)
canvas.SetImageBackgroundColor(bg)
canvas.SetImageFormat(i.mw.GetImageFormat())
x := (sz.Canvas.Width - int(i.mw.GetImageWidth())) / 2
y := (sz.Canvas.Height - int(i.mw.GetImageHeight())) / 2
canvas.CompositeImage(i.mw, imagick.COMPOSITE_OP_OVER, x, y)
canvas.ResetImagePage("")
}
if sz.Flatten {
break
}
}
if canvas != nil {
i.mw.Destroy()
i.mw = canvas
}
if coalesceAndDeconstruct {
// Compares each frame of the image, removes pixels that are already on the
// background and updates offsets accordingly.
i.mw = i.mw.DeconstructImages()
}
return nil
}