-
Notifications
You must be signed in to change notification settings - Fork 1
Performance
The performance of CaptchaN benefits a lot from the underlying project ImageSharp.
This page will show how to use CaptchaN in a perf-friendly way.
You need to provide your own font files(*.ttf
). Normally the fonts take little obvious effect on performance, but you should know that,
-
The style of fonts affects the speed of generating image.
-
The size/count of font files affects the memory use.
The lib generates images only for captcha, so it does not promise that it's able to create images of any aspect ratios. 120/160/200
are recommended for width, and 40/50/60
for height.
Certainly, smaller per image is, faster the lib generates.
The count of points takes a relatively lower cost than other elements. But the value is still recommended to be less or equal than 20
.
The first line must be Bezier Curve for the ultimate effect, and the others are straight lines for reducing cost. The value is recommended to be less or equal than 4
.
One bubble is a circular. The value is recommended to be less or equal than 6
.
It will create extra smaller code-chars as interference if the value is above zero. The perf depends on the count you decide and the fonts you provide. Normally, the value should be less or equal than 6
.
It won't use the ICodeTextGenerator
. Instead, it uses internal codes to random chars from the range of a-z
/A-Z
/0-9
.
If you just want to use a Black-White mode, or you want to use your own implementation of IColorRandomer
, you should realize that,
-
Black-White mode can reduce the cost of random
-
The count of color-kinds normally has little effect on the average size of image files
For captcha use, Jpeg
format is better than Png
because of smaller image file size. Jpeg
is enough for humankind, although Png
looks clearer.
The length of code text for captcha should always be short.
So the default CodeTextGenerator
uses 'stackalloc' in order to reduce heap memory use and GC pressure. It's best to take advantage of that if you want to implement your own one.
The Web API sample will produce an image with a size around 3K
each call. And intervals of most calls are around 5ms
on the localhost
environment. It should be a good reference to take.