"Draw" Chinese characters using the dot method in PHP

Source: Internet
Author: User
Nowadays, more and more people prefer to access the Internet, and more people have their own personal homepages. With the emergence of various automated software tools, making web pages easier and easier. However, because special effects are available everywhere, there are fewer and fewer innovative things. Maybe, someday, you will find that the counter on a website is exactly the same as your own SyntaxHighlighter. all (); Preface:
Nowadays, more and more people prefer to access the Internet, and more people have their own personal homepages. With the emergence of various automated software tools, making web pages easier and easier. However, because special effects are available everywhere, there are fewer and fewer innovative things. Maybe, someday, you will find that the counter on a website is exactly the same as your own. The more sophisticated the web page is. There are more and more things on the web page.
Question:
  • On the webpage, if I want to add a counter:
    In the past, I went to the space provider to get a link or copy an address from other places. However, this is always done by someone else. well, you don't have much say, you can only find them one by one.
  • On the webpage, I want to publish some information:
    If the information is text, create a new page and add a link;
    Is data. create a new page and add a link:
    But if the data is updated frequently, or even every hour or minute, it may change. are you willing to keep changing and uploading data in front of your computer? (We are not a commercial website. no one is willing to burn money for you .)
    However, message boards, chat rooms, and forums cannot be handled by HTML or JAVASCRIPT alone.

To achieve more automatic control, you can use cgi (currently not many people are using) (Common Gateway Interface) program to implement these functions.

Software Requirements:
Php (as the mainstream development language): GD Library
Configure a server that supports php (as the mainstream development language. I use OmniHTTPd Professional

For counters and real-time statistics and releases, we can use images to complete them. Output text in the image.
In php (as the mainstream development language), you need to create an image and display the dot content on it. The basic steps are as follows:

// The http header, telling the browser that this is a GIF image
Header ("Content-type: image/gif ");
// Do you want to draw a picture? Create a 400x300 color palette image
$ Im = imagecreate (400,300 );
$ Black = imagecolorallocate ($ im, 0, 0, 0 );
// The default black background.
// (The default value is the first defined color. If another color is defined before this line of code, the first color defined is the default background color .)
$ Red = imagecolorallocate ($ im, 255, 0, 0 );
// Red. If the two lines are exchanged, you will find that the background is red and the text is black.
$ String = "1234567890 ";
// The characters to be drawn
Imagestring ($ im, 12, 10, 10, $ string, $ red );
// Draw a string at (10, 10)
Imagepng ($ im );
// Output in png format. you can also use imagejpeg ($ im); or magegif ($ im). However, if the latter version is higher than 1.6, it cannot be used.
Imagedestroy ($ im );
// End, clear all occupied memory resources
?>


In the preceding example, a 12-pound "400" image is drawn from a point (10, 10 ". Have you noticed that the image size is 251 bytes! You can also try other output formats.
The image size depends on the number of non-background pixels in the image and the number of output pixels.

However, there is a problem.
You can use imagestring () to output the following information:
Imagestring ($ im, 1, 0, 0, "abcdefghijklmnopqrstuvwxyz0123456789 ~! @ # $ % ^ & * () _ + {} |: "<>? [];,./", $ Red );
However, you cannot output Chinese characters correctly !!!
Imagestring ($ im, 1, 0, 0, "ah", $ red );
What you see is by no means Chinese !! But garbled characters.
Php (as the mainstream development language) default character set is UTF-8, while Simplified Chinese is GB2312.

How can this problem be solved ?!
To solve this problem, you can let php (as the current mainstream development language) load the extension module php (as the current mainstream development language) _ iconv. dll (the suffix in UNIT is. SO), however, sometimes, it may not work properly. Originally, I wanted to put a piece of test code up, but this time I was not successful. To avoid errors, I still don't put them on.
However, the most critical thing is that if your space service provider disables the extension module or even disables the DL () function of the module, you can only follow the Chinese BYE-BYE.
Fortunately, there are other methods.
Character ING can be used to output characters in a pre-converted code table. However, you need a code table!
Or, draw every Chinese point manually! How is it ?!

Okay, come on, let's draw words together!

To draw a word, you must first know how to draw it.
Have you learned simple functions in junior high school? Do you want to draw a graph of a function? Calculate the coordinates of a point and connect the adjacent points. This method is called the plotting method.
What we need to do is calculate as many points as possible and then display them in the corresponding coordinates.
Have you ever heard of dot matrix printers and dot matrix Chinese characters?

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.