Talk about PHP drawing (2)_PHP tutorial
上次说了一种简单的回避GD的作图方法,而后又用GD作了最简单的一幅“图”——直线。 $style=array($col_red,$col_red,$col_black,$col_orn,$col_orn,$col_orn,$col_black); ImagePNG($im); 看看效果吧。 其中我用空行分割开的那三行,说明一下。定义了一个数组 $style,它的成员是一系列的颜色; 有了我详细讲解的画线的基础,我想把画其他几何图形的函数一笔代过。需要提示大家的是,无论 点,两个要素:横坐标、纵坐标 矩形,四个要素:左上角、右下角的横、纵坐标 弧,这样理解:弧可以包括圆弧、椭圆弧;画圆弧画他360度就可以成一个圆,画椭圆弧画他360度也就画 看下面这段例子。 Of course when drawing, it is inevitable to paint a certain area with a certain color. GD has three coloring methods, one is rectangular area coloring, Then: Let’s stop here this time.
这次我就接着画直线向下说。上次代码中详细解释过的部分,这次不再赘述。
Header("Content-type: image/png");
$im = ImageCreate (200, 100);
$col_black = ImageColorAllocate($im, 0,0,0);
$col_orn = ImageColorAllocate($im, 255,192,0);
// 今天用橘色吧。
// 跟 imageline 函数完全相同的用法,
ImageDashedLine($im,0,100,199,100,$col_orn);
// 这样就画了一条虚线。
// 下面我们来做个试验。用以说明一个问题。
$col_yel = ImageColorAllocate($im, 255,255,0);
// 黄色。
ImageLine($im,0,99,199,99,$col_yel);
// 在图象的最下沿画了一条黄色的线。
ImageLine($im,200,0,200,100,$col_orn);
// 试图在图象最右沿画一条澄色的线,结果什么也没有。
// 这表明,宽200,高100的图象,其坐标的范围是(0,0)到(199,99)。
ImagePNG($im);
ImageDestroy($im);
// 这一段先结束吧。
?>
接下来这个效果就爽了!我也是现学现卖。PHP4.0.6以上增加了这个用法——可以用交替的
颜色画线!示例如下:
Header("Content-type: image/png");
$im = ImageCreate (200, 100);
$col_black = ImageColorAllocate($im, 0,0,0);
$col_orn = ImageColorAllocate($im, 255,192,0);
$col_red = ImageColorAllocate($im, 255,0,0);
ImageSetStyle($im, $style);
ImageLine($im, 0, 50, 199, 50, IMG_COLOR_STYLED);
ImageDestroy($im);
?>
然后执行了一个函数,而后用 IMG_COLOR_STYLED “颜色”画出来的是这么神奇的“直线”——
红色、黑色、橙色交替的效果。仔细看一下你就会发现,红、黑、橙交替的顺序,就是我们定义的
$style数组成员的序列:红、红、黑、橙、橙、橙、黑,然后周而复始……
看明白了吗?注意,这个函数在PHP4.0.6以后才支持。
画哪种几何图形,无非是抓住这种图形的几个要素。先不算颜色,各种图形的要素如下:
成一个椭圆;所以这个弧的要素有六:中心点横、纵坐标,横轴长、纵轴长、弧的始、终点。
Header("Content-type: image/png");
$im = ImageCreate (200, 100);
$col_blk = ImageColorAllocate($im, 0,0,0);
$col_orn = ImageColorAllocate($im, 255,192,0);
$col_red = ImageColorAllocate($im, 255,0,0);
$col_grn = ImageColorAllocate($im, 0,255,0);
$col_blu = ImageColorAllocate($im, 0,0,255);
ImageSetPixel($im,20,10,$col_orn);
// 小小一个点,不知道能否看得见?
ImageRectangle($im,25,20,95,55,$col_blu);
// 蓝色的矩形。
ImageArc($im,20,85,50,40,225,360,$col_grn);
// 绿色的椭圆弧,中心在(20,85),横轴50,纵轴40,225度至360度。
// 由此可见,这里的圆弧始、终点是以角度计量,
// 是以水平向右的方向为0度,顺时针计算的。
ImageArc($im,160,60,40,40,0,360,$col_orn);
// 橙色的整圆。只要横轴长与纵轴长相等,就是正圆。
// 上高中我们就学过:圆是椭圆的特例嘛!
// 最后再画一段圆弧。圆心能否在图象以外?
ImageArc($im,160,140,240,240,0,360,$col_red);
// 可以!
ImagePNG($im);
ImageDestroy($im);
?>
one is coloring the enclosed area where the specified point is located, and the other is coloring the area surrounded by the specified color. Look at the following example:
Header("Content-type: image/png");
$im = ImageCreate (200, 100);
$col_blk = ImageColorAllocate($im , 0,0,0);
$col_orn = ImageColorAllocate($im, 255,192,0);
$col_yel = ImageColorAllocate($im, 255,255,0);
$col_red = ImageColorAllocate($im , 255,0,0);
$col_grn = ImageColorAllocate($im, 0,255,0);
$col_blu = ImageColorAllocate($im, 0,0,255);
ImageFilledRectangle($im ,20,10,100,50,$col_blu);
ImageFilledRectangle($im,5,40,50,90,$col_red);
ImageFilledRectangle($im,40,80,100,95,$col_orn);
ImageFilledRectangle($im,90,35,110,90,$col_yel);
// The above is the first coloring. Draw the rectangle directly.
// I deliberately surrounded a small area with four rectangles of different colors,
// to illustrate the second coloring.
ImagePNG($im);
ImageDestroy($im);
// Take a look at the effect.
?>
Header("Content-type: image/png");
$im = ImageCreate (200, 100);
$col_blk = ImageColorAllocate($im, 0,0, 0);
$col_orn = ImageColorAllocate($im, 255,192,0);
$col_yel = ImageColorAllocate($im, 255,255,0);
$col_red = ImageColorAllocate($im, 255,0, 0);
$col_grn = ImageColorAllocate($im, 0,255,0);
$col_blu = ImageColorAllocate($im, 0,0,255);
ImageFilledRectangle($im,20,10,100, 50,$col_blu);
ImageFilledRectangle($im,5,40,50,90,$col_red);
ImageFilledRectangle($im,40,80,100,95,$col_orn);
ImageFilledRectangle($ im,90,35,110,90,$col_yel);
// The above is the first coloring. Draw the rectangle directly.
// I deliberately surrounded a small area with four rectangles of different colors,
> // to illustrate the second coloring.
ImageFill($im,70,70,$col_grn);
// This is the second coloring.
ImageRectangle($im,120,40,190,90,$col_grn);
// Let’s draw a rectangle to make the frame. In fact, any shape of border can be used as a frame.
ImageFilltoBorder($im,130,50,$col_grn,$col_orn);
// Paint the green rectangle orange.
// As long as the specified point is within the scope of this "box", it has nothing to do with the position of the point in the area.
// This function actually works like this:
// Starting from the specified point, looking outwards for the boundary of the specified color. If found, stop.
// If not found, just The points passing by are painted in the required color.
ImagePNG($im);
ImageDestroy($im);
// Take a look at the effect.
// Now the picture we made is colorful, but in the browser, on the picture,
// Right-click -> Properties: only 214 bytes!
?>

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

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

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

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

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

In this chapter, we are going to learn the following topics related to routing ?

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

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

Validator can be created by adding the following two lines in the controller.
