Home Backend Development PHP Tutorial 'Draw' Chinese using the point tracing method in PHP_PHP Tutorial

'Draw' Chinese using the point tracing method in PHP_PHP Tutorial

Jul 13, 2016 pm 05:29 PM
php Chinese author Preface exist source Now draw transcend

Author: LuciferStar Source: Beyond PHP Preface: Now, more and more people like to go online, and more and more people have their own personal homepages. With the emergence of various automated software tools, making web pages is becoming easier and easier. However, since special effects are widely available, there are fewer and fewer innovative things. Maybe, one day, you will find that the counter on a website is exactly the same as yours. The web page is becoming more and more mature. There are more and more things on the web, and they are becoming richer and richer. Question: On a web page, if I want to add a counter: In the past, I would go to the space provider and ask for a link, or copy the address from other places, but these are always done by others, okay? Those who don’t have much say can only find them one by one. On the web page, I want to publish some information: If the information is text, create a new page and add a link; if it is data, create a new page and add a link: But if the data is updated frequently, even every hour, It may change every minute. Are you willing to stay in front of the computer, constantly modifying and uploading? (We are not a commercial website, no one is willing to spend money for you.) Message boards, chat rooms, forums, these cannot be accomplished by HTML and JAVASCRIPT alone. In order to achieve more automatic control, CGI (Common Gateway Interface) programs can be used to implement these functions. Software requirements: PHP: GD Library configures a server that supports PHP. I use OmniHTTPd Professional for counters and real-time data statistics and publishing, which we can do with images. Output text in the picture. In PHP, to create a picture and display point content on it, the basic steps are as follows: In the above example, on a 400×300 picture, starting from point (10, 10), draw a 12-point "1234567890" . Did you notice that the size of this image is: 251 bytes! You can also try other output formats. The size of the picture is related to the number of non-background pixels in the picture, and has nothing to do with how many pixels are output. 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 correctly!!! imagestring($im,1,0,0,"Ah",$red); What you see is definitely not Chinese!! But garbled characters . The default character set of PHP is UTF-8, and Simplified Chinese is GB2312. How to solve this problem? In order to solve this problem, you can let PHP load the extension module php_iconv.dll (the suffix name under UNIT is .SO). Sometimes, it may not work properly. Originally, I was going to put a piece of test code, but this time, it didn't work. In order to avoid errors, I didn't put them up. But the most fatal thing is that if your If the space service provider closes the extension module, or even disables the DL() function of the loading module, then you can only BYE-BYE with Chinese. Fortunately, there are other ways to pre-install it through character mapping. The characters in the converted code table are output. But, you need a code table! How about drawing every point of the Chinese characters by hand? Okay, let’s draw the characters together! First of all, you need to know how to draw. Have you learned about simple functions in junior high school? Have you ever done this? Calculate the coordinates of a certain point and then connect two adjacent points. This method is called the point drawing method. It is to calculate as many points as possible and then display them at the corresponding coordinates. Have you ever heard of dot matrix printers and dot matrix Chinese characters? When outputting Chinese characters, they are represented by points at a certain coordinate. The function to display a point of a certain color is: int imagesetpixel (resource image, int x, int y, int color) Suppose I want to display a white point at coordinates (100,100), then, I only need the following code: In other words, as long as we obtain the information of all points of a certain Chinese character, we can output that Chinese character through this function.In the file chs16.fon, what is saved is the national standard location code table (national standard Chinese character encoding basic character set for information exchange GB-2312). It is a dot matrix font library for Chinese characters. (In WIN98 system, this file is under c:windowscommand. If you want to use it under UNIX system, please pay attention to the case. If not, you can find the link at the end of the article.) It is from the MSDOS era, but, well Things should still be taken out and used. From chs16.fon, we can read the lattice data of Chinese characters. Each Chinese character is composed of 16×16 dots. Where the stroke passes, the value of the point is 1, otherwise it is 0; each point occupies one bit, and every 8 points constitute a byte. Then, a Chinese character requires (16×16÷8=32) bytes. The following example is to illustrate the representation method of character dot matrix. Here, an 8×8 matrix is ​​defined, showing a letter C. The white square is represented by 0, and the black square is represented by 1. Then, the codes of these eight lines of graphics are: Line binary represents hexadecimal represents 0 00000000 0x00 1 00111110 0x3E 2 01110000 0xE0 3 01110000 0xE0 4 01110000 0xE0 5 01110000 0xE0 6 00111110 0x3E 7 00000000 0 x00 To output these points, you need to draw the first line first, then the second line, the third line... to the last line . Use a loop: for($hang=0;$hang "location code" to index and search. As mentioned before, a Chinese character takes up 32 bytes in the table, so we define a character containing 32 Array of elements: $buffer=array(0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0 ,0,0,0,0, 0,0,0,0,0, 0,0); used to save the 32-byte data read from the font library. The next question is, where is a certain character stored? Where in the file? Since a Chinese character uses 32 bytes, and the GB-2312 area code table has 94 rows and 94 columns, then, as long as you know the number of the character in the table, then multiply by 32. . So define the offset: $offset=(94*($qh-1)+($wh-1))*32; $qh represents the area (qu), $wh represents the bit (wei); minus 1, This is because PHP starts counting from 0. To find the position, you only need to use the fseek() function to set the position in the code table, and then read 32 bytes into $buffer. In addition, since Chinese is composed of two bytes. The dot matrix example given earlier is 8 bits, one byte, so the code for drawing dots needs to be modified: for($hang=0;$hang

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/531714.htmlTechArticleAuthor: LuciferStar Source: Beyond PHP Preface: Now, more and more people like to surf the Internet. Many people have their own personal homepage. With the emergence of various automation software tools...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

7 PHP Functions I Regret I Didn't Know Before 7 PHP Functions I Regret I Didn't Know Before Nov 13, 2024 am 09:42 AM

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

See all articles