Zend_captcha_image usage and partial function rewriting Based on Zend framework 1.6

Source: Internet
Author: User

Before doing this, first take a look at the official documentation

Zend_captcha_image

The image adapter parses the generated character into an image and converts it into an image that is hard to be automatically decrypted. It requires» GD extension, which can be compiled using TrueType or FreeType. Currently, the image adapter can only generate PNG images.

Zend_captcha_image integrates zend_captcha_word and attaches the following methods:

Setexpiration ($ Expiration) And getexpiration () specify the maximum lifecycle of the CAPTCHA image that can be retained in the file system. It is generally longer than the session lifecycle. Each time a CAPTCHA object is called, spam runs once, and expired images are cleared. The expiration value is in seconds.

Setgcfreq ($ Gcfreq) And getgcfreg () Specify the frequency of garbage collection. Each1/$ GcfreqGarbage collection runs once (default value:100).

Setfont ($ Font) And getfont () Specify the font to use. It is the full path to the font file. If this value is not set, CAPTCHA throws an exception during generation. The font is required.

Setfontsize ($ Fsize) And getfontsize () Specify the font size, in pixels, used to generate CAPTCHA. The default value is 24px.

Setheight ($ Height) And getheight () Specify the height of the generated CAPTCHA image, in pixels. The default value is 50px.

Setwidth ($ Width) And getwidth () Specify the width of the generated CAPTCHA image, in pixels. The default value is 200px.

Setimgdir ($ Imgdir) And getimgdir () Specify the directory for storing CAPTCHA images. Default Value:"./Images/CAPTCHA/", Relative to the bootstrap script.

Setimgurl ($ Imgurl) And getimgurl () Specify the relative path of the CAPTCHA image used for the HTML markup language. Default Value:"/Images/CAPTCHA/".

Setsuffix ($ Suffix) And getsuffix () Specify the filename suffix. Default Value:". PNG". Note: Its changes do not affect the image type.

All the above options can be passed to the constructor as an option, as long as you remove'Set'Method prefix and change the first letter to lower case: for example"Suffix","Height","Imgurl".

General Usage

$ Font_dir = Realpath ( Dirname ( _ File __ ) . ' Http://www.cnblogs.com/www/font/simsun.ttc ' );
$ Im = New Zend_captcha_image ( Array (
' Font ' => $ Font_dir ,
' Fontsize ' => 14 ,
' Wordlen ' => 4 ,
' Height ' => 20 ,
' Width ' => 60
));

$ Im -> Generate ();
Return   $ Im -> Getimgurl () . $ Im -> GETID () . $ Im -> Getsuffix ();

FAQs:

    1. Noise, too many interference lines, a little unclear
    2. The image content cannot be standardized.
    3. You cannot set the font curvature of an image.

Solution

Update tomorrow.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.