PHP drawing technology examples explained
Learn vector pictures (verification codes), draw and generate reports. Hope this article can help everyone.
Steps
创建画布 会只需要的各种图形(圆,直线,矩形,弧线,扇形) 输出图像到网页,也可以另存 销毁图片(释放内存)
Picture format
gif 图片压缩率高, 但是只能显示256色可能造成颜色丢失,但可以显示动画 jpg/jpeg 图片的压缩率高,可以用较小的文件来显示 网页上用的比较多 png,高仿真 综合了gif和jpg的优势,但是不能显示动画
Quick Start
创建画布$img = imagecreatetruecolor(100,100); 取色$red = imagecolorallocate($img, 255, 0, 0); 画图 •imagefilledarc — 画一椭圆弧且填充 •imagefilledellipse — 画一椭圆并填充 •imagefilledpolygon — 画一多边形并填充 •imagefilledrectangle — 画一矩形并填充 输出到浏览器header("content-type: image/png"); imagepng($img); 销毁 imagedestroy($img);
Picture to canvas
$srcImage = imagecreatefromgif(filename);$srcImage_info = getimagesize(filename); imagecopy(dst_im, src_im, dst_x, dst_y, src_x, src_y, src_w, src_h); 具体参数含义 不懂看文档
Writing
imagettftext(image, size, angle, x, y, color, fontfile, text)
Generate verification code
<?php /** * Created by PhpStorm. * User: draymonder * Date: 2018/3/1 * Time: 15:15 */ $checkcode =""; for($i=0;$i<4;$i++){ $checkcode.= dechex(rand(0,15)); } $img = imagecreatetruecolor(200,30); //背景颜色 $bgcolor = imagecolorallocate($img,0,0,0); imagefill($img,0,0,$bgcolor); //添加干扰线 for($i=0;$i<10;$i++){ $color = imagecolorallocate($img,rand(0,255),rand(0,255),rand(0,255)); imageline($img,rand(0,200),rand(0,30),rand(0,200),rand(0,30),$color); } //白色,字体颜色 $white = imagecolorallocate($img,255,255,255); //添加字符串 imagestring($img,rand(4,6),rand(0,180),rand(0,20),$checkcode,$white); header("content-type: image/png"); imagepng($img); imagedestroy($img); ?>
Related recommendations:
Examples of php drawing technology
Key points and applications of drawing technology in php Summary
Common functions of php drawing technology
The above is the detailed content of PHP drawing technology examples explained. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



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

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

To work on file upload we are going to use the form helper. Here, is an example for file upload.

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

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.

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

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

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,
