Open s3rj1k opened 5 years ago
I would try just rendering each character separately, using a per-character rotational transform. You won't get proper kerning without some work, but the per-character rotation will likely mean using regular kerning makes the whole thing look silly anyhow. (Many captchas I've seen have fixed spacing between letters, though there's no reason that spacing can also be randomly perturbed.)
@jpap that was my initial approach, I failed on rotating per character :))
Have you looked at the examples/rotated-text.go
example?
For N
characters, I'd imagine you have a loop over n \in N
and do something like:
Push()
a new context.Translate()
to move across one character space.RotateAbout()
.n
-th character using DrawStringAnchored()
.Pop()
the old context back.@jpap exactly what I did, but the rotation angle seems off with every next letter.
Maybe a missed Translate()
...
@s3rj1k any update on this ussie? Did you figure out how to rotate several objects in different angles?
@tagaism I think I did not used rotation in the end, but the issue is still valid.
for _, char := range str {
dc.Push()
dc.RotateAbout(gg.Radians(20 * rand.Float64()), 0, (stdHeight/2))
dc.SetRGBA(0, 0, 0, (rand.Float64()) / 2 + 0.25)
dc.DrawStringAnchored(string(char), spacePerChar / 2, float64(stdHeight/2), 0.5, 0.5)
dc.Pop()
dc.Translate(spacePerChar, 0)
}
This seems to be working. You have to play around with things a little bit to reset the rotation angle but not the place translation.
How to rotate multiple string characters in different angles?
Can you provide example with multiple string objects rotated by 10/-10 degrees that are located in one line?
Use case for captcha generation.