?php$img = imagecreatetruecolor(600, 600); //创建一个600px * 600px 的真彩色图像$cornflowerblue = imagecolorallocate($img, 100,149,237);imagefill($img, 0, 0, $cornflowerblue); //填充背景色//imagefill($img, 30, 30, $cornflowerblue); 和上面一
<?php
$img = imagecreatetruecolor(600, 600); //创建一个600px * 600px 的真彩色图像
$cornflowerblue = imagecolorallocate($img, 100,149,237);
imagefill($img, 0, 0, $cornflowerblue); //填充背景色
//imagefill($img, 30, 30, $cornflowerblue); 和上面一行代码的效果一样,中间的数字参数的改变对填充背景色没有影响
header('Content-Type:image/png'); //告诉浏览器以什么方式显示
imagepng($img); //PNG 格式将图像输出到浏览器或文件
imagedestroy($img); //销毁图像资源
?><?php
$img = imagecreate(600, 600);
$cornflowerblue = imagecolorallocate($img, 100,149,237); //第一个颜色就默认为图片的背景颜色
$magenta = imagecolorallocate($img, 255, 0, 255);
$springgreen = imagecolorallocate($img, 0, 255, 127);
header('Content-Type:image/png');
imagepng($img);
imagedestroy($img);
?>通过上面两段代码,我想表达imagecreatetruecolor()和imagecreate()创建的图像,添加背景颜色的区别。
下面的代码是从(10, 10 )开始画一个100px * 100px 的正方形,正方形的100px*100px 包括边框的像素。而这个正方形的边框是1像素,空白像素加两个边框的2个像素就是100像素:
<?php
$img = imagecreatetruecolor(600, 600);
$cornflowerblue = imagecolorallocate($img, 100,149,237);;
$black = imagecolorallocate($img, 0, 0, 0);
imagefill($img, 0, 0, $cornflowerblue); //填充背景色
imagerectangle($img, 10, 10, 109, 109, $black);
header('Content-Type:image/png');
imagepng($img);
imagedestroy($img);
?><?php …… imagerectangle($img, 0, 0, 600 - 1, 600 - 1, $black); //图片的长和宽减1 …… ?>
再看:
<?php …… imagesetpixel($img, 200, 300, $black); …… ?>
画圆时:
<?php…… imageellipse($img, 200, 200, 100, 100, $black); …… ?>
再来看画线时GD函数的表现:
立即学习“PHP免费学习笔记(深入)”;
<?php …… imageline($img, 300, 300, 400, 400, $black); …… ?>
再来看imagefilledarc()函数:
<?php …… imagefilledarc($img, 200, 300, 300, 200, 0, 120, $black, IMG_ARC_PIE); //imagefilledarc($img, 200, 300, 300, 200, 0, 120, $black, IMG_ARC_CHORD); //imagefilledarc($img, 200, 300, 300, 200, 0, 120, $black, IMG_ARC_NOFILL); //imagefilledarc($img, 200, 300, 300, 200, 0, 120, $black, IMG_ARC_EDGED); …… ?>
来看一个有误差的函数 imagechar():
<?php …… imagechar($img, 5, 100, 200, 'Z', $black); …… ?>
imagefontheight(int $font) 返回指定字体一个字符高度的像素值 如:imagefontheight(15) 将返回15。
PHP是一种功能强大的网络程序设计语言,而且易学易用,移植性和可扩展性也都非常优秀,本书将为读者详细介绍PHP编程。 全书分为预备篇、开始篇和加速篇三大部分,共9章。预备篇主要介绍一些学习PHP语言的预备知识以及PHP运行平台的架设;开始篇则较为详细地向读者介绍PKP语言的基本语法和常用函数,以及用PHP如何对MySQL数据库进行操作;加速篇则通过对典型实例的介绍来使读者全面掌握PHP。 本书
486
array imagettftext( resource$image ,float$size ,float$angle
,int$x ,int$y ,int$color
,string$fontfile ,string$text ),其中的 x, y 手册的解释是:
x:由 x,y 所表示的坐标定义了第一个字符的基本点(大概是字符的左下角)。这和imagestring不同,其 x,y 定义了第一个字符的左上角。例如 "top left" 为 0, 0。
y:Y 坐标。它设定了字体基线的位置,不是字符的最底端。
我一看到那基线就把我给弄蒙了,查了一下资料,请看下图:
实际显示时,像素还是有一些偏差。毕竟像素只是一个相对单位,它和显示器的分辨率有关,有时出现误差也是在所难免,但在标准的一像素的情况下,了解一下php GD库的这些函数的参数标准还是很有必要的。
当然GD中还有很多其它的函数,这里我也就不一一细说了,大家有什么好的想法,或我的行文有错误,希望大家不吝指出,我不胜感激。
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号