php画弧
① php图像处理函数有哪些
我在网上找了半天,发现这些都无法实现对它的认识,于是我偶然间找到了相关的资料方面的书;
那就是PHP 手册,表在网上找这些没用的东西了,全是些皮毛介绍,误人子弟;
请点击这里:网页链接下载相关的手册,或者在网上查找PHP相关的中文版的手册;
又全面又仔细,不需要在网上乱查了,根本就是浪费时间,误入歧途.
例子 1. 用 PHP 创建 PNG 图像
<?phpheader("Content-type: image/png");
$string = $_GET['text'];
$im= imagecreatefrompng("images/button1.png");
$orange = imagecolorallocate($im,
220, 210, 60);
$px= (imagesx($im) - 7.5
* strlen($string)) /
2;
imagestring($im, 3, $px, 9, $string, $orange);
imagepng($im);
imagedestroy($im);
?>
本例应该在一个具有类似:<img
src="button.php?text=text"> 标签的页面中被调用。上述的 button.php 脚本会取得 "text"
字符串将其覆盖在原图上(本例中的
"images/button1.png")并输出作为结果的图像。用此方法可以很方便地修改按钮上的文字从而避免了每次都要新画一个按钮的图像。用此方法就可以动态生成了。
目录
exif_imagetype--判断一个图像的类型
exif_read_data-- 从 JPEG 或 TIFF 文件中读取 EXIF 头信息,这样就可以读取数码相机产生的元数据
exif_thumbnail--取得嵌入在 TIFF 或
JPEG 图像中的缩略图gd_info--取得当前安装的 GD 库的信息
getimagesize--取得图像大小
image_type_to_mime_type-- 取得
getimagesize,exif_read_data,exif_thumbnail,exif_imagetype 所返回的图像类型的 MIME 类型image2wbmp--以 WBMP 格式将图像输出到浏览器或文件
imagealphablending--设定图像的混色模式
imageantialias--是否使用 antialias
功能imagearc--画椭圆弧
imagechar--水平地画一个字符
imagecharup--垂直地画一个字符
imagecolorallocate--为一幅图像分配颜色
imagecolorallocatealpha--为一幅图像分配颜色
+ alphaimagecolorat--取得某像素的颜色索引值
imagecolorclosest--取得与指定的颜色最接近的颜色的索引值
imagecolorclosestalpha--取得与指定的颜色
+ alpha 最接近的颜色imagecolorclosesthwb--
取得与给定颜色最接近的色度的黑白色的索引imagecolordeallocate--取消图像颜色的分配
imagecolorexact--取得指定颜色的索引值
imagecolorexactalpha--取得指定的颜色 +
alpha 的索引值imagecolormatch--
使一个图像中调色板版本的颜色与真彩色版本更能匹配imagecolorresolve--
取得指定颜色的索引值或有可能得到的最接近的替代值imagecolorresolvealpha--
取得指定颜色 + alpha 的索引值或有可能得到的最接近的替代值imagecolorset--给指定调色板索引设定颜色
imagecolorsforindex--取得某索引的颜色
imagecolorstotal--取得一幅图像的调色板中颜色的数目
imagecolortransparent--将某个颜色定义为透明色
image--拷贝图像的一部分
imagemerge--拷贝并合并图像的一部分
imagemergegray--用灰度拷贝并合并图像的一部分
imageresampled--重采样拷贝部分图像并调整大小
imageresized--拷贝部分图像并调整大小
imagecreate--新建一个基于调色板的图像
imagecreatefromgd2--从 GD2
文件或 URL 新建一图像imagecreatefromgd2part--从给定的
GD2 文件或 URL 中的部分新建一图像imagecreatefromgd--从 GD 文件或
URL 新建一图像imagecreatefromgif--从 GIF
文件或 URL 新建一图像imagecreatefromjpeg--从
JPEG 文件或 URL 新建一图像imagecreatefrompng--从 PNG
文件或 URL 新建一图像imagecreatefromstring--从字符串中的图像流新建一图像
imagecreatefromwbmp--从
WBMP 文件或 URL 新建一图像imagecreatefromxbm--从 XBM
文件或 URL 新建一图像imagecreatefromxpm--从 XPM
文件或 URL 新建一图像imagecreatetruecolor--新建一个真彩色图像
imagedashedline--画一虚线
imagedestroy--销毁一图像
imageellipse--画一个椭圆
imagefill--区域填充
imagefilledarc--画一椭圆弧且填充
imagefilledellipse--画一椭圆并填充
imagefilledpolygon--画一多边形并填充
imagefilledrectangle--画一矩形并填充
imagefilltoborder--区域填充到指定颜色的边界为止
imagefontheight--取得字体高度
imagefontwidth--取得字体宽度
imageftbbox--取得使用了 FreeType 2
字体的文本的范围imagefttext--使用 FreeType 2
字体将文本写入图像imagegammacorrect--对 GD 图像应用
gamma 修正imagegd2--输出 GD2 图像
imagegd--将 GD 图像输出到浏览器或文件
imagegif--以 GIF 格式将图像输出到浏览器或文件
imageinterlace--激活或禁止隔行扫描
imageistruecolor--检查图像是否为真彩色图像
imagejpeg--以 JPEG 格式将图像输出到浏览器或文件
imagelayereffect-- Set the
alpha blending flag to use the bundled libgd layering effectsimageline--画一条直线
imageloadfont--载入一新字体
imagepalette--将调色板从一幅图像拷贝到另一幅
imagepng--以 PNG 格式将图像输出到浏览器或文件
imagepolygon--画一个多边形
imagepsbbox--取得使用 PostScript Type1
字体的文本的范围imagepsfont--
拷贝一个已加载的字体以备更改imagepsencodefont--改变字体中的字符编码矢量
imagepsextendfont--扩充或压缩字体
imagepsfreefont--释放一个
PostScript Type 1 字体所占用的内存imagepsloadfont--从文件中加载一个
PostScript Type 1 字体imagepsslantfont--倾斜某字体
imagepstext--用 PostScript Type1
字体把文本字符串画在图像上imagerectangle--画一个矩形
imagerotate--用给定角度旋转图像
imagesavealpha-- 设置标记以在保存 PNG
图像时保存完整的 alpha 通道信息(与单一透明色相反)imagesetbrush--设定画线用的画笔图像
imagesetpixel--画一个单一像素
imagesetstyle--设定画线的风格
imagesetthickness--设定画线的宽度
imagesettile--设定用于填充的贴图
imagestring--水平地画一行字符串
imagestringup--垂直地画一行字符串
imagesx--取得图像宽度
imagesy--取得图像高度
imagetruecolortopalette--将真彩色图像转换为调色板图像
imagettfbbox--取得使用 TrueType
字体的文本的范围imagettftext--用 TrueType
字体向图像写入文本imagetypes--返回当前 PHP 版本所支持的图像类型
imagewbmp--以 WBMP 格式将图像输出到浏览器或文件
iptcembed--将二进制 IPTC 数据嵌入到一幅 JPEG
图像中iptcparse-- 将二进制 IPTC http://www.iptc.org/ 块解析为单个标记
jpeg2wbmp--将 JPEG 图像文件转换为 WBMP 图像文件
png2wbmp--将 PNG 图像文件转换为 WBMP 图像文件
read_exif_data--exif_read_data() 的别名
② 在PHOTOSHOP中怎样把画布的四个角变成圆弧角
这个我会啦!你把图片拉到PS后,按住Ctrl同时点击当前图层,此时当前图层成为选区,松开Ctrl.然后Ctrl+Alt+D羽化选区,Ctrl+Shift+I反相选区,直接按Delete.然后再适当的将图层放大,看你想要的效果了!!我的这个方法绝对OK!我以前做过啊!
③ 如何在PHP中开启GD库支持详解
开启GD库是php中一个重要的参数,常用来处理图像,像图片的任何处理都需要GD库的支持,下面我来介绍各种系统中GD库的开启方法与命令,大家可参考。
Windows下开启PHP的GD库支持
找到php.ini,打开内容,找到:
;extension=php_gd2.dll
把最前面的分号“;”去掉,再保存即可,如果本来就没有分号,那就是已经开启了。
linux下开启PHP的GD库支持
#开启GD库支持有以下几种方法
##检测GD库是否安装命令
php5 -m | grep -i gd
或者
php -i | grep -i --color gd
##如未安装GD库,则为服务器安装,方法如下
### 如果是源码安装,则加入参数
--with-gd
### 如果是debian系的linux系统,用apt-get安装,如下
apt-get install php5-gd
### 如果是CentOS系的系统,用yum安装,如下
yum install php-gd
### 如果是suse系的linux系统,用yast安装,如下
yast -i php5_gd
### 如果嫌这个世界不够蛋疼呢,可以在原先编译PHP不支持GD的情况下附加
先下zlib源码,libpng源码,gd源码
解压后到源码目录
zlib目录
./configure --prefix=/usr/local/zlib
make ; make install
make clean
libpng目录
cp scripts/makefile.linux ./makefile
./configure --prefix=/usr/local/libpng
make ; make install
make clean
gd目录
./configure --prefix=/usr/local/libgd --with-png=/usr/local/libpng
make ; make install
make clean
最后在php.ini中,搜到[gd]后,在下面加一行
extension=/usr/local/libgdgd.so
然后重启php服务,如果不行,试试reboot
好了,不过最后提醒一下,要知道这个世界很多意外的,源码安装,只添加gd库这一个情况下,PHP版本和库的版本各异
,所以:
- 不保证这么付出了这么多后有回报
- 不保证能够成功加载gd.so
- 不保证不怀孕
所以如果是源码安装,最好还是在编译PHP的时候加参数--with-gd
GD库函数
GetImageSize
作用:取得图片的大小[即长与宽] 用法:array GetImageSize(string filename, array [imageinfo]);
ImageArc
作用:画弧线 用法:int ImageArc(int im, int cx, int cy, int w, int h, int s, int e, int col);
ImageChar
作用:写出横向字符 用法:int ImageChar(int im, int font, int x, int y, string c, int col);
ImageCharUp
作用:写出竖式字符 用法:int ImageCharup(int im, int font, int x, int y, string c, int col);
ImageColorAllocate
作用:匹配颜色 用法:int ImageColorAllocate(int im, int red, int green, int blue);
ImageColorTransparent
作用:指定透明背景色 用法:int ImageColorTransparent(int im, int [col]);
ImageCopyResized
作用:复制新图并调整大小 用法:int ImageCopyResized(int dst_im, int src_im, int dstX, int dstY, int srcX,
int srcY, int dstW, int dstH, int srcW, int srcH);
ImageCreate
作用:建立新图 用法:int ImageCreate(int x_size, int y_size);
ImageDashedLine
作用:绘虚线 用法:int ImageDashedLine(int im, int x1, int y1, int x2, int y2, int col);
ImageDestroy 作用:结束图形 用法解释:int ImageDestroy(int im);
ImageFill
作用:图形着色 用法:int ImageFill(int im, int x, int y, int col);
ImageFilledPolygon作用:多边形区域着色 用法:int ImageFilledPolygon(int im, array points, int num_points,
int col);
ImageFilledRectangle作用:矩形区域着色 用法:int ImageFilledRectangle(int im, int x1, int y1, int x2, int
y2, int col);
ImageFillToBorder作用:指定颜色区域内着色 用法:int ImageFillToBorder(int im, int x, int y, int border,
int col);
ImageFontHeight
作用:取得字型的高度 用法:int ImageFontHeight(int font);
ImageFontWidth作用:取得字型的宽度 用法:int ImageFontWidth(int font);
ImageInterlace作用:使用交错式显示与否 用法:int ImageInterlace(int im, int [interlace]);
ImageLine作用:绘实线 用法:int ImageLine(int im, int x1, int y1, int x2, int y2, int col);
ImageLoadFont作用:载入点阵字型 用法:int ImageLoadFont(string file);
ImagePolygon作用:绘多边形 用法:int ImagePolygon(int im, array points, int num_points, int col);
ImageRectangle作用:绘矩形 用法:int ImageRectangle(int im, int x1, int y1, int x2, int y2, int col);
ImageSetPixel作用:绘点 用法:int ImageSetPixel(int im, int x, int y, int col); ImageString 作用:绘横式
字符串 用法:int ImageString(int im, int font, int x, int y, string s, int col);
ImageStringUp作用:绘直式字符串 用法:int ImageStringUp(int im, int font, int x, int y, string s, int
col);
ImageSX
作用:取得图片的宽度 用法:int ImageSX(int im);
ImageSY
作用:取得图片的高度 用法:int ImageSY(int im);
ImageTTFBBox
作用:计算 TTF 文字所占区域 用法:array ImageTTFBBox(int size, int angle, string fontfile, string text);
ImageTTFText作用:写 TTF 文字到图中 用法:array ImageTTFText(int im, int size, int angle, int x, int y,
int col, string fontfile, string text); ImageColorAt 作用:取得图中指定点颜色的索引值 用法:int
ImageColorAt(int im, int x, int y);
ImageColorClosest
作用:计算色表中与指定颜色最接近者 用法:int ImageColorClosest(int im, int red, int green, int blue);
ImageColorExact
作用:计算色表上指定颜色索引值 用法:int ImageColorExact(int im, int red, int green, int blue);
ImageColorResolve
作用:计算色表上指定或最接近颜色的索引值 用法:int ImageColorResolve(int im, int red, int green, int
blue);
ImageColorSet
作用:设定色表上指定索引的颜色 用法:boolean ImageColorSet(int im, int index, int red, int green, int
blue); ImageColorsForIndex 作用:取得色表上指定索引的颜色 用法:array ImageColorsForIndex(int im, int
index);
ImageColorsTotal
作用:计算图的颜色数 用法:int ImageColorsTotal(int im); ImagePSLoadFont 作用:载入 PostScript 字型 用法
:int ImagePSLoadFont(string filename);
ImagePSFreeFont
作用:卸下 PostScript 字型 用法:void ImagePSFreeFont(int fontindex);
ImagePSEncodeFont
作用:PostScript 字型转成向量字 用法:int ImagePSEncodeFont(string encodingfile);
ImagePSText作用:写 PostScript 文字到图中 用法:array ImagePSText(int image, string text, int font, int
size, int foreground, int background, int x, int y, int space, int tightness, float angle, int
antialias_steps);
ImagePSBBox作用:计算 PostScript 文字所占区域 用法: array ImagePSBBox(string text, int font, int size,
int space, int width, float angle);
ImageCreateFromPNG作用:取出 PNG 图型 用法:int ImageCreateFromPng(string filename);
ImagePNG作用:建立 PNG 图型 用法:int ImagePng(int im, string [filename]);
ImageCreateFromGIF作用:取出 GIF 图型 用法:int ImageCreateFromGif(string filename);
ImageGIF作用:建立 GIF 图型 用法:int ImageGif(int im, string [filename]);
④ php中imagettftext()函数的使用~ 呢
共有8个参数,缺一不可:
(1)$image 这个是画布资源,无需再解释;
(2)$size,官方文档的解释是,字体大小,其长度单位依赖于GD库的版本,对于GD1来说是像素,对于GD2来说是磅(point)。现在一般都是GD2了,那么这个磅究竟是什么意思呢?这涉及到字体设计的基本知识。
操作位图时,以像素位单位最精确合理,那么使用GD2库的时候,如何绘制大小为20像素的字呢?也就是多少磅才能等于20个像素呢?这必须通过分辨率才能计算出来,而问题是位图本身并没有分辨率的概念。
现在把问题返回来,如果给定$size=20磅,那么imageTtfText()绘制完成时,究竟会占用多少像素。无论如何,imageTtfText()最终还是要把文字绘制落实到具体的位图像素上。
这个问题确实非常棘手,此函数内部必然会使用某个分辨率PPI来计算被渲染的像素区域。而GD2库却没有提供任何让用户设置或者读取这个分辨率的方法。那么,我们只能动手测试了。使用不同的磅值绘制文字,然后测量文字占据的像素,通过公式:
PPI = (72*像素数)/磅值。实验得出的结论是:
[plain] view plainprint?
1磅==>4像素, PPI=288
2磅==>5像素, PPI=180
3磅==>7像素, PPI=168
4磅==>8像素, PPI=144
5磅==>9像素, PPI=129.6
6磅==>10像素, PPI=120
7磅==>11像素, PPI=113.14285714286
8磅==>12像素, PPI=108
9磅==>14像素, PPI=112
10磅==>15像素, PPI=108
11磅==>16像素, PPI=104.72727272727
12磅==>17像素, PPI=102
13磅==>18像素, PPI=99.692307692308
14磅==>19像素, PPI=97.714285714286
15磅==>21像素, PPI=100.8
16磅==>22像素, PPI=99
17磅==>23像素, PPI=97.411764705882
18磅==>25像素, PPI=100
19磅==>26像素, PPI=98.526315789474
20磅==>27像素, PPI=97.2
21磅==>28像素, PPI=96
22磅==>29像素, PPI=94.909090909091
23磅==>30像素, PPI=93.913043478261
24磅==>32像素, PPI=96
25磅==>33像素, PPI=95.04
26磅==>34像素, PPI=94.153846153846
27磅==>35像素, PPI=93.333333333333
28磅==>36像素, PPI=92.571428571429
29磅==>38像素, PPI=94.344827586207
30磅==>39像素, PPI=93.6
31磅==>40像素, PPI=92.903225806452
32磅==>41像素, PPI=92.25
33磅==>43像素, PPI=93.818181818182
34磅==>44像素, PPI=93.176470588235
35磅==>46像素, PPI=94.628571428571
36磅==>47像素, PPI=94
37磅==>48像素, PPI=93.405405405405
38磅==>48像素, PPI=90.947368421053
39磅==>50像素, PPI=92.307692307692
40磅==>51像素, PPI=91.8
41磅==>52像素, PPI=91.317073170732
42磅==>53像素, PPI=90.857142857143
43磅==>55像素, PPI=92.093023255814
44磅==>56像素, PPI=91.636363636364
45磅==>57像素, PPI=91.2
46磅==>58像素, PPI=90.782608695652
47磅==>60像素, PPI=91.914893617021
48磅==>62像素, PPI=93
49磅==>63像素, PPI=92.571428571429
50磅==>63像素, PPI=90.72
51磅==>64像素, PPI=90.352941176471
52磅==>67像素, PPI=92.769230769231
53磅==>68像素, PPI=92.377358490566
54磅==>69像素, PPI=92
55磅==>70像素, PPI=91.636363636364
56磅==>71像素, PPI=91.285714285714
57磅==>72像素, PPI=90.947368421053
58磅==>74像素, PPI=91.862068965517
59磅==>75像素, PPI=91.525423728814
60磅==>76像素, PPI=91.2
61磅==>77像素, PPI=90.885245901639
62磅==>78像素, PPI=90.58064516129
63磅==>79像素, PPI=90.285714285714
64磅==>81像素, PPI=91.125
65磅==>83像素, PPI=91.938461538462
66磅==>84像素, PPI=91.636363636364
67磅==>85像素, PPI=91.34328358209
68磅==>86像素, PPI=91.058823529412
69磅==>86像素, PPI=89.739130434783
70磅==>88像素, PPI=90.514285714286
71磅==>90像素, PPI=91.267605633803
72磅==>91像素, PPI=91
73磅==>92像素, PPI=90.739726027397
74磅==>93像素, PPI=90.486486486486
1磅==>4像素, PPI=288
2磅==>5像素, PPI=180
3磅==>7像素, PPI=168
4磅==>8像素, PPI=144
5磅==>9像素, PPI=129.6
6磅==>10像素, PPI=120
7磅==>11像素, PPI=113.14285714286
8磅==>12像素, PPI=108
9磅==>14像素, PPI=112
10磅==>15像素, PPI=108
11磅==>16像素, PPI=104.72727272727
12磅==>17像素, PPI=102
13磅==>18像素, PPI=99.692307692308
14磅==>19像素, PPI=97.714285714286
15磅==>21像素, PPI=100.8
16磅==>22像素, PPI=99
17磅==>23像素, PPI=97.411764705882
18磅==>25像素, PPI=100
19磅==>26像素, PPI=98.526315789474
20磅==>27像素, PPI=97.2
21磅==>28像素, PPI=96
22磅==>29像素, PPI=94.909090909091
23磅==>30像素, PPI=93.913043478261
24磅==>32像素, PPI=96
25磅==>33像素, PPI=95.04
26磅==>34像素, PPI=94.153846153846
27磅==>35像素, PPI=93.333333333333
28磅==>36像素, PPI=92.571428571429
29磅==>38像素, PPI=94.344827586207
30磅==>39像素, PPI=93.6
31磅==>40像素, PPI=92.903225806452
32磅==>41像素, PPI=92.25
33磅==>43像素, PPI=93.818181818182
34磅==>44像素, PPI=93.176470588235
35磅==>46像素, PPI=94.628571428571
36磅==>47像素, PPI=94
37磅==>48像素, PPI=93.405405405405
38磅==>48像素, PPI=90.947368421053
39磅==>50像素, PPI=92.307692307692
40磅==>51像素, PPI=91.8
41磅==>52像素, PPI=91.317073170732
42磅==>53像素, PPI=90.857142857143
43磅==>55像素, PPI=92.093023255814
44磅==>56像素, PPI=91.636363636364
45磅==>57像素, PPI=91.2
46磅==>58像素, PPI=90.782608695652
47磅==>60像素, PPI=91.914893617021
48磅==>62像素, PPI=93
49磅==>63像素, PPI=92.571428571429
50磅==>63像素, PPI=90.72
51磅==>64像素, PPI=90.352941176471
52磅==>67像素, PPI=92.769230769231
53磅==>68像素, PPI=92.377358490566
54磅==>69像素, PPI=92
55磅==>70像素, PPI=91.636363636364
56磅==>71像素, PPI=91.285714285714
57磅==>72像素, PPI=90.947368421053
58磅==>74像素, PPI=91.862068965517
59磅==>75像素, PPI=91.525423728814
60磅==>76像素, PPI=91.2
61磅==>77像素, PPI=90.885245901639
62磅==>78像素, PPI=90.58064516129
63磅==>79像素, PPI=90.285714285714
64磅==>81像素, PPI=91.125
65磅==>83像素, PPI=91.938461538462
66磅==>84像素, PPI=91.636363636364
67磅==>85像素, PPI=91.34328358209
68磅==>86像素, PPI=91.058823529412
69磅==>86像素, PPI=89.739130434783
70磅==>88像素, PPI=90.514285714286
71磅==>90像素, PPI=91.267605633803
72磅==>91像素, PPI=91
73磅==>92像素, PPI=90.739726027397
74磅==>93像素, PPI=90.486486486486
可见当大于46磅时,PPI稳定在90,而小于46磅时,PPI一直在微变。
所以,如果你想绘制20个像素大小的字体,那么必须设置$size参数为:14.5磅。
另外需要注意的是,$size并不完全对应字体的显示大小,因为同样的$size,不同的字符占据的空间并不是一样的。例如,汉字“国”的宽度会比数字1的宽度大得多,对于标点符号,则更是这样,半角和全角符号也不同。
总之,使用imageTtfText()不可能精确控制到像素级别,只能大概。这也算是矢量字体的一个小缺陷。
(3)$angle是旋转角度。这个官网解释的比较清楚,需要说明有两点:一是角度单位是度而不是弧度,二是旋转的中心点就是参数$x,$y。
(4)$x,$y 被绘制字符串的第一个字符的基线点。单位是像素。这里涉及到字体设计的基本知识--基线。这个点绝对不是左上角,而具体是什么取决于所使用的字体是如何设计的。对于宋体、楷体、黑体等常见的字体中的汉字,这个点大概位于字体的左下部分;而对于英文字母和标点符号,则各不相同。如下图:
(5)$color 字体的颜色。
(6)$fontfile 字体文件。也就是包含trueType字体字模的文件,如楷体字体文件simkai.ttf。这种文件的格式是有标准规范的,而且与平台无关。所以可以直接把Windows系统的字体文件拷贝到Linux下使用。
(7)$text 要渲染的字符串。需要注意必须是UTF-8编码的字符串。说到字符串不得不提PHP的string数据类型。虽然名为string,其实PHP语言本身并不认识各种字符编码,它只是简单的把string看做是动态增长的“字节”数组,例如strlen()就是返回的字节数。而我们知道除了ASCII编码的字符和字节是相同的外,几乎没有其他字符编码中的字符对应一个字节,例如一个汉字的UTF-8编码占用3个字节。至于怎么解释其中的字符编码,需要专门的库函数如iconv_strlen()。如果字符串使用字面量,那么其所在的php源文件就必须编码为UTF-8存储。
⑤ php生成图片输出到前端页面乱码
是生成的图像里面有乱码,还是页面有乱码?图像里面有乱码在生成图片那里声明下编码格式:header("charset=UTF-8");
页面有乱码声明下页面的格式:header("Content-Type: text/html; charset=UTF-8");
两者是有区别的。
⑥ 如何在PHP中开启GD库支持
Windows下开启PHP的GD库支持
找到php.ini,打开内容,找到:
;extension=php_gd2.dll
把最前面的分号“;”去掉,再保存即可,如果本来就没有分号,那就是已经开启了。
Linux下开启PHP的GD库支持
#开启GD库支持有以下几种方法
##检测GD库是否安装命令
php5 -m | grep -i gd
或者
php -i | grep -i --color gd
##如未安装GD库,则为服务器安装,方法如下
### 如果是源码安装,则加入参数
--with-gd
### 如果是debian系的linux系统,用apt-get安装,如下
apt-get install php5-gd
### 如果是CentOS系的系统,用yum安装,如下
yum install php-gd
### 如果是suse系的linux系统,用yast安装,如下
yast -i php5_gd
### 如果嫌这个世界不够蛋疼呢,可以在原先编译PHP不支持GD的情况下附加
先下zlib源码,libpng源码,gd源码
解压后到源码目录
zlib目录
./configure --prefix=/usr/local/zlib
make ; make install
make clean
libpng目录
cp scripts/makefile.linux ./makefile
./configure --prefix=/usr/local/libpng
make ; make install
make clean
gd目录
./configure --prefix=/usr/local/libgd --with-png=/usr/local/libpng
make ; make install
make clean
最后在php.ini中,搜到[gd]后,在下面加一行
extension=/usr/local/libgdgd.so
然后重启php服务,如果不行,试试reboot
好了,不过最后提醒一下,要知道这个世界很多意外的,源码安装,只添加gd库这一个情况下,PHP版本和库的版本各异
,所以:
- 不保证这么付出了这么多后有回报
- 不保证能够成功加载gd.so
- 不保证不怀孕
所以如果是源码安装,最好还是在编译PHP的时候加参数--with-gd
GD库函数
GetImageSize
作用:取得图片的大小[即长与宽] 用法:array GetImageSize(string filename, array [imageinfo]);
ImageArc
作用:画弧线 用法:int ImageArc(int im, int cx, int cy, int w, int h, int s, int e, int col);
ImageChar
作用:写出横向字符 用法:int ImageChar(int im, int font, int x, int y, string c, int col);
ImageCharUp
作用:写出竖式字符 用法:int ImageCharup(int im, int font, int x, int y, string c, int col);
ImageColorAllocate
作用:匹配颜色 用法:int ImageColorAllocate(int im, int red, int green, int blue);
ImageColorTransparent
作用:指定透明背景色 用法:int ImageColorTransparent(int im, int [col]);
ImageCopyResized
作用:复制新图并调整大小 用法:int ImageCopyResized(int dst_im, int src_im, int dstX, int dstY, int srcX,
int srcY, int dstW, int dstH, int srcW, int srcH);
ImageCreate
作用:建立新图 用法:int ImageCreate(int x_size, int y_size);
ImageDashedLine
作用:绘虚线 用法:int ImageDashedLine(int im, int x1, int y1, int x2, int y2, int col);
ImageDestroy 作用:结束图形 用法解释:int ImageDestroy(int im);
ImageFill
作用:图形着色 用法:int ImageFill(int im, int x, int y, int col);
ImageFilledPolygon作用:多边形区域着色 用法:int ImageFilledPolygon(int im, array points, int num_points,
int col);
ImageFilledRectangle作用:矩形区域着色 用法:int ImageFilledRectangle(int im, int x1, int y1, int x2, int
y2, int col);
ImageFillToBorder作用:指定颜色区域内着色 用法:int ImageFillToBorder(int im, int x, int y, int border,
int col);
ImageFontHeight
作用:取得字型的高度 用法:int ImageFontHeight(int font);
ImageFontWidth作用:取得字型的宽度 用法:int ImageFontWidth(int font);
ImageInterlace作用:使用交错式显示与否 用法:int ImageInterlace(int im, int [interlace]);
ImageLine作用:绘实线 用法:int ImageLine(int im, int x1, int y1, int x2, int y2, int col);
ImageLoadFont作用:载入点阵字型 用法:int ImageLoadFont(string file);
ImagePolygon作用:绘多边形 用法:int ImagePolygon(int im, array points, int num_points, int col);
ImageRectangle作用:绘矩形 用法:int ImageRectangle(int im, int x1, int y1, int x2, int y2, int col);
ImageSetPixel作用:绘点 用法:int ImageSetPixel(int im, int x, int y, int col); ImageString 作用:绘横式
字符串 用法:int ImageString(int im, int font, int x, int y, string s, int col);
ImageStringUp作用:绘直式字符串 用法:int ImageStringUp(int im, int font, int x, int y, string s, int
col);
ImageSX
作用:取得图片的宽度 用法:int ImageSX(int im);
ImageSY
作用:取得图片的高度 用法:int ImageSY(int im);
ImageTTFBBox
作用:计算 TTF 文字所占区域 用法:array ImageTTFBBox(int size, int angle, string fontfile, string text);
ImageTTFText作用:写 TTF 文字到图中 用法:array ImageTTFText(int im, int size, int angle, int x, int y,
int col, string fontfile, string text); ImageColorAt 作用:取得图中指定点颜色的索引值 用法:int
ImageColorAt(int im, int x, int y);
ImageColorClosest
作用:计算色表中与指定颜色最接近者 用法:int ImageColorClosest(int im, int red, int green, int blue);
ImageColorExact
作用:计算色表上指定颜色索引值 用法:int ImageColorExact(int im, int red, int green, int blue);
ImageColorResolve
作用:计算色表上指定或最接近颜色的索引值 用法:int ImageColorResolve(int im, int red, int green, int
blue);
ImageColorSet
作用:设定色表上指定索引的颜色 用法:boolean ImageColorSet(int im, int index, int red, int green, int
blue); ImageColorsForIndex 作用:取得色表上指定索引的颜色 用法:array ImageColorsForIndex(int im, int
index);
ImageColorsTotal
作用:计算图的颜色数 用法:int ImageColorsTotal(int im); ImagePSLoadFont 作用:载入 PostScript 字型 用法
:int ImagePSLoadFont(string filename);
ImagePSFreeFont
作用:卸下 PostScript 字型 用法:void ImagePSFreeFont(int fontindex);
ImagePSEncodeFont
作用:PostScript 字型转成向量字 用法:int ImagePSEncodeFont(string encodingfile);
ImagePSText作用:写 PostScript 文字到图中 用法:array ImagePSText(int image, string text, int font, int
size, int foreground, int background, int x, int y, int space, int tightness, float angle, int
antialias_steps);
ImagePSBBox作用:计算 PostScript 文字所占区域 用法: array ImagePSBBox(string text, int font, int size,
int space, int width, float angle);
ImageCreateFromPNG作用:取出 PNG 图型 用法:int ImageCreateFromPng(string filename);
ImagePNG作用:建立 PNG 图型 用法:int ImagePng(int im, string [filename]);
ImageCreateFromGIF作用:取出 GIF 图型 用法:int ImageCreateFromGif(string filename);
ImageGIF作用:建立 GIF 图型 用法:int ImageGif(int im, string [filename]);
⑦ php三维饼图怎么做要调入数据库的数据!请高手指点!不会的别来混经验!
这是个2D的。
其中有一个自定义函数,用于绘制饼图,参数是一个键值对数组。
每项内容是由数组定义的。你调入数据库中的内容后读入数组即可。
前提是你当然要开启GD扩展,要不是没得画得。呵。
<?php
function pie2d($a) //创建自定义函数
{
$im=imagecreate(420,300); //建立图像
$back=imagecolorallocate($im,255,255,200); //背景色
$color[]=imagecolorallocate($im,0,0,255); //定义10个颜色,可以最多处理10项
$color[]=imagecolorallocate($im,255,0,0);
$color[]=imagecolorallocate($im,0,255,0);
$color[]=imagecolorallocate($im,100,100,255);
$color[]=imagecolorallocate($im,255,0,255);
$color[]=imagecolorallocate($im,150,0,0);
$color[]=imagecolorallocate($im,0,0,150);
$color[]=imagecolorallocate($im,0,150,0);
$color[]=imagecolorallocate($im,0,0,0);
$color[]=imagecolorallocate($im,150,150,150);
$value_a=array_values($a); //获取参数数组所有值到新数组
$all=array_sum($value_a); //统计新数组的和
$i=0; //循环标记
foreach($a as $key=>$value) //遍历数组
{
$angle[]=$value/$all*360; //获取当前角度
$str=$key.":".round($value/$all*100,2)."%"; //需要输出的内容
imagestring($im,5,10,($i*20+10),$str,$color[$i]); //画字符串
$i++; //标记自增
}
$s=0; //当前角度标记
$i=0;
foreach($angle as $temp) //遍历所有项角度
{
imagefilledarc($im,285,150,240,120,$s,($s+$temp),$color[$i],4); //画椭圆弧
//imagefillellipse();
$s=$s+$temp; //角度增加为当前角度
$i++;
}
imagepng($im); //输出PNG
imagedestroy($im); //销毁图像
}
$arr=array(
"perfect"=>1,
"excellent"=>2,
"very good"=>4,
"good"=>1,
"not bad"=>1,
"normal"=>1,
"bad"=>1,
"very bad"=>1,
"god save me"=>1,
"hell"=>1
); //定义数组,数组内容为选项内容与选项数量的键值对
$re=pie2d($arr); //调用自定义函数
?>