Skip to content

Performance

LeaFrock edited this page Apr 9, 2021 · 13 revisions

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.

Fonts

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.

PainterOption

Width/Height

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.

Point

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.

Point Demo

Line

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.

Line Demo

Bubble

One bubble is a circular. The value is recommended to be less or equal than 6.

Bubble Demo

Interfer Chars

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.

IC Demo

Color

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

BW Demo

Image Format

CodeTextGenerator

Web API sample

The Web API sample will produce an image with a size around 3K each call. And intervals of most calls are below 10ms. It should be a good reference to take.

Clone this wiki locally