Verification Code-php Image Generation Problems

Source: Internet
Author: User
The server is ubuntu. If php is installed using the source code, you can see that the gd library is enabled. However, when an image is generated, it cannot be displayed, and a thumbnail with the wrong number is displayed. There is no problem with the same code on the local machine. Look at the code. I pasted it, but this code is problematic...

If the server is ubuntu and php is installed using the source code, you can see that the gd library is enabled,


However, when an image is generated, it cannot be displayed, and a thumbnail with an incorrect number is displayed. There is no problem with the same code on the local machine.

Look at the code. I pasted it, but this code is unlikely to be a problem. The same Code can be used to produce images in my development environment. My biggest problem is that I cannot see the error log? It is unclear what the error is. It's just a problem with the gd library.

/* Image Verification Code Powered By KASON test http://www.jbxue.com */Session_start (); $ num = 4; // number of verification codes $ width = 80; // Verification code width $ height = 20; // Verification code height $ code = ''; for ($ I = 0; $ I <$ num; $ I ++) // generates the verification code {switch (rand () {case 0: $ code [$ I] = chr (rand (); break; // number case 1: $ code [$ I] = chr (rand (); break; // case 2: $ code [$ I] = chr (rand (97,122); break; // lowercase letter }}$ _ SESSION ["VerifyCode"] = $ code; $ image = imagecreate ($ width, $ height); imagecolorallocate ($ image, 255,255,255 ); for ($ I = 0; $ I <80; $ I ++) // generates interference pixels {$ dis_color = imagecolorallocate ($ image, rand (0,255), rand (0,255); imagesetpixel ($ image, rand (1, $ width), rand (1, $ height), $ dis_color);} for ($ I = 0; $ I <$ num; $ I ++) // print characters to the image {$ char_color = imagecolorallocate ($ image, rand (0,255), rand (0,255); imagechar ($ image, 60, ($ width/$ num) * $ I, rand (0, 5), $ code [$ I], $ char_color);} header ("Content-type: image/gif "); // replace it with png here, and replace the following method with imagepn G. Imagegif ($ image); // output the image to the browser imagedestroy ($ image); // release the resource?>

There is no problem with the Code. The problem is the configuration of php and gd. The biggest problem is that there is no way to solve the problem.

Reply content:

If the server is ubuntu and php is installed using the source code, you can see that the gd library is enabled,


However, when an image is generated, it cannot be displayed, and a thumbnail with an incorrect number is displayed. There is no problem with the same code on the local machine.

Look at the code. I pasted it, but this code is unlikely to be a problem. The same Code can be used to produce images in my development environment. My biggest problem is that I cannot see the error log? It is unclear what the error is. It's just a problem with the gd library.

/* Image Verification Code Powered By KASON test http://www.jbxue.com */Session_start (); $ num = 4; // number of verification codes $ width = 80; // Verification code width $ height = 20; // Verification code height $ code = ''; for ($ I = 0; $ I <$ num; $ I ++) // generates the verification code {switch (rand () {case 0: $ code [$ I] = chr (rand (); break; // number case 1: $ code [$ I] = chr (rand (); break; // case 2: $ code [$ I] = chr (rand (97,122); break; // lowercase letter }}$ _ SESSION ["VerifyCode"] = $ code; $ image = imagecreate ($ width, $ height); imagecolorallocate ($ image, 255,255,255 ); for ($ I = 0; $ I <80; $ I ++) // generates interference pixels {$ dis_color = imagecolorallocate ($ image, rand (0,255), rand (0,255); imagesetpixel ($ image, rand (1, $ width), rand (1, $ height), $ dis_color);} for ($ I = 0; $ I <$ num; $ I ++) // print characters to the image {$ char_color = imagecolorallocate ($ image, rand (0,255), rand (0,255); imagechar ($ image, 60, ($ width/$ num) * $ I, rand (0, 5), $ code [$ I], $ char_color);} header ("Content-type: image/gif "); // replace it with png here, and replace the following method with imagepn G. Imagegif ($ image); // output the image to the browser imagedestroy ($ image); // release the resource?>

There is no problem with the Code. The problem is the configuration of php and gd. The biggest problem is that there is no way to solve the problem.

The information is still not enough to determine the problem. I feel that there should be an error message before the header, causing the image to be unable to be displayed. You can try to debug it like this:

  1. Do not put the img label inside to debug, direct browser access requests output picture PHP, http://www.host.com/code.php
  2. Insession_start();Add oneerror_reporting(E_ALL);ini_set("display_errors","On");Check whether there are any errors.

It should be your server configuration. Everything works on my ubuntu server.

Reference: generating image thumbnails in php

PHP image processing phpThumb parameter usage
Implementation of the php Image Upload Function
Php uploads images with watermarks and supports transparent code.
Php code for uploading images and adding transparent watermarks
Php Image Watermarking and uploading Image Watermarking
Php uses the GD library to generate an image in bmp format (imagebmp)
Code for uploading images and creating thumbnails in the php GD library

Related Article

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.