PHP Generation Verification Code reference PHP manual

Source: Internet
Author: User

The view layer is copied and pasted to

phpStudy2013 GD Support does not open the workaround
Phpstudyadmin Console-configuration file-php.ini
Find "Extension=php_gd2.dll", remove "Extension=php_gd2.dll" in front of ";", save
Phpstudyadmin console-MySQL service-restart
Phpstudyadmin Console-Apache service-restart
Problem solving

And then take action

<?php
Set the Content-type

Header (' Content-type:image/png charset=utf-8 ');

Create the image
$im = Imagecreatetruecolor (100, 100);

Create some colors
$white = Imagecolorallocate ($im, 255, 255, 255);
$grey = Imagecolorallocate ($im, 128, 128, 128);
$black = imagecolorallocate ($im, 0, 0, 0);
Imagefilledrectangle ($im, 0, 0, 399, $white);

The text to draw
$text = ' 1231231231231 ';
Replace path by your own font path
$font = ' Arial.ttf ';

Add some shadow to the text
Imagettftext ($im, 0, one, one, $grey, $font, $text);

Add the text
Imagettftext ($im, 0, $black, $font, $text);

Using imagepng () results in clearer text compared with imagejpeg ()
Ob_clean ();
Imagepng ($im);
Imagedestroy ($im);
?>

!! If the report does not show write on Ob_clean (), if garbled removed BOM head (at that time did not know, did not try)

Or

<? Php

Create a new Image instance
$im = Imagecreatetruecolor (100, 100);

Set the background to white
Imagefilledrectangle ($im, 0, 0, 0xFFFFFF);

Write on an image
Imagestring ($im, 3, +, ' GD Library ', 0xffba00);

Output image to Browser
Header (' content-type:image/gif ');

Imagegif ($im);
Imagedestroy ($im);

?>

PHP Generation Verification Code reference PHP manual

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.