Exemplo n.º 1
0
Arquivo: image.go Projeto: npk/captcha
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
	}
}
Exemplo n.º 2
0
// 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
	}
}
Exemplo n.º 3
0
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
}