详细解释imageTtfText()函数
1)$image这个是画布资源
2)$size,官方文档的解释是,字体大小
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.782608
(3)$angle是旋转角度。这个官网解释的比较清楚,需要说明有两点:一是角度单位是度而不是弧度,二是旋转的中心点就是参数$x,$y。
(4)(5)$x,$y 被绘制字符串的第一个字符的基线点。单位是像素。
(6)$color 字体的颜色,不多解释。
(7)$fontfile 字体文件。也就是包含trueType字体字模的文件,如楷体字体文件simkai.ttf。这种文件的格式是有标准规范的,而且与平台无关。所以可以直接把Windows系统的字体文件拷贝到Linux下使用。
(8)$text 要渲染的字符串。需要注意必须是UTF-8编码的字符串。说到字符串不得不提PHP的string数据类型。虽然名为string,其实PHP语言本身并不认识各种字符编码,它只是简单的把string看做是动态增长的“字节”数组,例如strlen()就是返回的字节数。而我们知道除了ASCII编码的字符和字节是相同的外,几乎没有其他字符编码中的字符对应一个字节,例如一个汉字的UTF-8编码占用3个字节。至于怎么解释其中的字符编码,需要专门的库函数如iconv_strlen()。如果字符串使用字面量,那么其所在的php源文件就必须编码为UTF-8存储。
int imagecolorallocate(int im, int red, int green, int blue);本函数用来匹配图形的颜色,供其它绘图函数使用。参数 im 表示图形的 handle。参数 red、green、blue 是色彩三原色,其值从 0 至 255。
imagedestroy() 函数用于销毁图像资源。
magecopy() 函数用于拷贝图像或图像的一部分。
imagecopyresized() 函数用于拷贝部分图像并调整大小。
imagecopy()
imagecopy() 函数用于拷贝图像或图像的一部分,成功返回 TRUE ,否则返回 FALSE 。
语法:bool imagecopy( resource dst_im, resource src_im, int dst_x, int dst_y, int src_x, intsrc_y,int src_w, intsrc_h )
参数说明:参数说明
dst_im目标图像
src_im被拷贝的源图像
dst_x目标图像开始 x 坐标
dst_y目标图像开始 y 坐标,x,y同为0则从左上角开始
src_x拷贝图像开始 x 坐标
src_y拷贝图像开始 y 坐标,x,y同为0则从左上角开始拷贝
src_w(从 src_x 开始)拷贝的宽度
src_h(从 src_y 开始)拷贝的高度
例子:<?php
header("Content-type: image/jpeg");//创建目标图像
$dst_im = imagecreatetruecolor(150, 150);//源图像
$src_im = @imagecreatefromjpeg("images/flower_1.jpg");//拷贝源图像左上角起始 150px 150px
imagecopy( $dst_im, $src_im, 0, 0, 0, 0, 150, 150);//输出拷贝后图像
imagejpeg($dst_im);
imagedestroy($dst_im);
imagedestroy($src_im);?>imagecopyresized()
imagecopyresized() 函数用于拷贝图像或图像的一部分并调整大小,成功返回 TRUE ,否则返回 FALSE 。
语法:bool imagecopyresized( resource dst_im, resource src_im, int dst_x, int dst_y, int src_x, intsrc_y,int dst_w, int dst_h, int src_w, intsrc_h )
本函数参数可参看 imagecopy() 函数,只是本函数增加了两个参数(注意顺序):
dst_w:目标图像的宽度。
dst_h:目标图像的高度。
imagecopyresized() 的典型应用就是生成图片的缩略图:<?php
header("Content-type: image/jpeg");//原图文件
$file = "images/flower_1.jpg";//缩略图比例
$percent = 0.5;//缩略图尺寸
list($width, $height) =getimagesize($file);
$newwidth= $width *$percent;
$newheight= $height *$percent;//加载图像
$src_im =@imagecreatefromjpeg($file);
$dst_im=imagecreatetruecolor($newwidth, $newheight);//调整大小
imagecopyresized($dst_im, $src_im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);//输出缩小后的图像
imagejpeg($dst_im);
imagedestroy($dst_im);
imagedestroy($src_im);?>
resource imagecreatetruecolor ( int $width , int $height )新建一个真彩色图像
PHP 输出图像
PHP 允许将图像以不同格式输出:
imagegif():以 GIF 格式将图像输出到浏览器或文件
imagejpeg():以 JPEG 格式将图像输出到浏览器或文件
imagepng():以 PNG 格式将图像输出到浏览器或文件
imagewbmp():以 WBMP 格式将图像输出到浏览器或文件
语法:
原文:http://www.cnblogs.com/benpaodegegen/p/6432848.html