㈠ php 图象处理函数 imagestring 函数的运用
可以用imagettftext来生成,支持truetype字体
array imagettftext ( resource image, float size, float angle, int x, int y, int color, string fontfile, string text )
image
图像资源。见 imagecreatetruecolor()。
size
字体大小。根据 GD 版本不同,应该以像素大小指定(GD1)或点大小(GD2)。
angle
角度制表示的角度,0 度为从左向右读的文本。更高数值表示逆时针旋转。例如 90 度表示从下向上读的文本。
x
由 x,y 所表示的坐标定义了第一个字符的基本点(大概是字符的左下角)。这和 imagestring() 不同,其 x,y 定义了第一个字符的左上角。例如 "top left" 为 0, 0。
y
Y 坐标。它设定了字体基线的位置,不是字符的最底端。
color
颜色索引。使用负的颜色索引值具有关闭防锯齿的效果。见 imagecolorallocate()。
fontfile
是想要使用的 TrueType 字体的路径。
根据 PHP 所使用的 GD 库的不同,当 fontfile 没有以 / 开头时则 .ttf 将被加到文件名之后并且会在库定义字体路径中尝试搜索该文件名。
当使用的 GD 库版本低于 2.0.18 时,一个空格字符 而不是分号将被用来作为不同字体文件的“路径分隔符”。不小心使用了此特性将会导致一条警告信息:Warning: Could not find/open font。对受影响的版本来说唯一解决方案就是将字体移动到不包含空格的路径中去。
很多情况下字体都放在脚本的同一个目录下。下面的小技巧可以减轻包含的问题。 <?php
// Set the enviroment variable for GD
putenv('GDFONTPATH=' . realpath('.'));
// Name the font to be used (note the lack of the .ttf extension)
$font = 'SomeFont';
?>
text
文本字符串。
可以包含十进制数字化字符表示(形式为:€)来访问字体中超过位置 127 的字符。UTF-8 编码的字符串可以直接传递。
如果字符串中使用的某个字符不被字体支持,一个空心矩形将替换该字符。
imagettftext() 返回一个含有 8 个单元的数组表示了文本外框的四个角,顺序为坐下角,右下角,右上角,左上角。这些点是相对于文本的而和角度无关,因此“左上角”指的是以水平方向看文字时其左上角。
例子 1. imagettftext() 例子
本例中的脚本将生成一个白色的 400x30 像素 PNG 图像,其中有黑色(带灰色阴影)Arial 字体写的“Testing...”。
<?php
// Set the content-type
header("Content-type: image/png");
// Create the image
$im = imagecreatetruecolor(400, 30);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
// The text to draw
$text = 'Testing...';
// Replace path by your own font path
$font = 'arial.ttf';
// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>
㈡ php图像生成函数imagecreatetruecolor和imagecreate的区别
1、如果你用过smarty模板引擎、MVC类似框架如tp,那么你自己写一个框架噢! 2、你要对php的继承实现以及其中的小知识点熟知; 3、先列出你的框架目录,什么地方放什么,然后写你的配置文件 4、用到的高频函数有:require 、 require_once 、 file_exites等! 如:sybase_connect连上数据库。 语法: int sybase_connect(string [servername], string [username], string [password]); 返回值: 整数函数种类: 数据库功能 本函数用来打开与 Sybase 数据库的连接。 参数 servername 为欲连上的数据库服务器名称。 参数 username 及 password 可省略,分别为连接使用的帐号及密码。 使用本函数需注意早点关闭数据库,以减少系统的负担。 连接成功则返回数据库的连接代号,失败返回 false 值。
㈢ PHP图像处理函数有哪些
php图像处理函数大全
php图片处理代码分享,包括缩放、剪裁、缩放、翻转、旋转、透明、锐化等。需要的朋友可以参考下
一、创建图片资源
imagecreatetruecolor(width,height);
imagecreatefromgif(图片名称);
imagecreatefrompng(图片名称);
imagecreatefromjpeg(图片名称);画出各种图像
imagegif(图片资源,保存路径);
imagepng()
imagejpeg();
二、获取图片属性
imagesx(res//宽度
imagesy(res//高度
getimagesize(文件路径)
返回一个具有四个单元的数组。索引
0 包含图像宽度的像素值,索引 1 包含图像高度的像素值。索引 2 是图像类型的标记:1 = GIF,2 = JPG,3 = PNG,4 = SWF,5 =
PSD,6 = BMP,7 = TIFF(intel byte order),8 = TIFF(motorola byte order),9 = JPC,10
= JP2,11 = JPX,12 = JB2,13 = SWC,14 = IFF,15 = WBMP,16 = XBM。这些标记与 PHP 4.3.0 新加的
IMAGETYPE 常量对应。索引 3 是文本字符串,内容为“height="yyy" width="xxx"”,可直接用于 IMG
标记。
销毁图像资源
imagedestroy(图片资源);
三、透明处理
PNG、jpeg透明色都正常,只有gif不正常
imagecolortransparent(resource
image [,int
color])//将某个颜色设置成透明色
imagecolorstotal()
imagecolorforindex();
四、图片的裁剪
imageresized()
imageresampled();
五、加水印(文字、图片)
字符串编码转换string iconv ( string $in_charset ,
string $out_charset , string $str )
六、图片旋转
imagerotate();//制定角度的图片翻转
七、图片的翻转
沿X轴 沿Y轴翻转
八、锐化
imagecolorsforindex()
imagecolorat()
㈣ 在php中图像处理新建一个画布用什么函数
$newImage=imagecreatetruecolor($xSize,$ySize);
//增加一个白色的底,不然新建的画布是黑色的
$white=imagecolorallocate($newImage,255,255,255);
imagefill($newImage,0,0,$white);
图像处理也经常使用到imagemerge、getimagesize、imagecreatefromjpeg等函数,建议你看下这个链接,全是图像处理的函数http://php.net/manual/zh/ref.image.php
㈤ 关于php函数中的imageinterlace($image,int bit);
imageinterlace -- 激活或禁止隔行扫描
说明
int imageinterlace ( resource image [, int interlace] )
imageinterlace() 打开或关闭隔行扫描的比特标记。如果 interlace 为 1 则图像为隔行扫描的,如果 interlace 为 0 则图像为非隔行扫描的。
如果设定了隔行扫描比特标记而图像使用 JPEG 格式,则图像被创建为渐进式 JPEG。
本函数返回图像中是否设定了隔行扫描比特标记。
㈥ php图像生成函数imagecreatetruecolor和imagecreate的区别
resource imagecreatetruecolor ( int $x_size , int $y_size )
返回一个图像标识符,代表了一幅大小为 x_size 和 y_size 的黑色图像。
resource imagecreate ( int $x_size , int $y_size )
返回一个图像标识符,代表了一幅大小为
两者在改变背景颜色时有些区别:
imagecreatetruecolor需要用imagefill()来填充颜色
imagecreate()需要用imagecolorAllocate()添加背景色
php案例如下:
<?php$img = imagecreatetruecolor(100,100); //创建真彩图像资源$color = imagecolorAllocate($img,200,200,200); //分配一个灰色imagefill($img,0,0,$color); // 从左上角开始填充灰色header('content-type:image/jpeg'); //jpg格式imagejpeg($img); //显示灰色的方块?>
<?php$img = imagecreate(100,100);imagecolorallocate($img,200,200,200);header('content-type:image/jpeg'); imagejpeg($img); ?>
http://www.phpddt.com/php/imagecreate.html
㈦ php函数绘图显示图像后就不能return了吗
没具体测试过,不过道理上应该是可以return的。仔细检查一下代码呗,或者你贴上来大家帮你看看。
imagepng只是把内容输出了,并没有退出php进程,再说imagepng函数本身也会返回true/false。
补充一点,一般来说绘图函数就是负责绘图,生成随机字符的函数负责生成,不应该将这两个功能放到一个函数里。从流程上,应该先调用随机字符函数获取字符串,然后将字符串传递给绘图函数要求它绘制。
㈧ php图像生成函数imagecreatetruecolor和imagecreate的区别
用imagecreatetruecolor(int x,int y)建立的是一幅大小为 x和 y的黑色图像(默认为黑色),如想改变背景颜色则需要用填充颜色函数imagefill($img,0,0,$color);
imagecreate 新建一个空白图像资源,用imagecolorAllocate()添加背景色
上面两个函数只不过是一个功能的两种方法
具体用法见以下两种方法:
<?php
$img = imagecreatetruecolor(100,100); //创建真彩图像资源
$color = imagecolorAllocate($img,200,200,200); //分配一个灰色
imagefill($img,0,0,$color); // 从左上角开始填充灰色
header('content-type:image/jpeg'); //jpg格式
imagejpeg($img); //显示灰色的方块
?>
<?php
$img = imagecreate(100,100);
$color = imagecolorallocate($img,200,200,200);
header('content-type:image/jpeg'); //jpg格式
imagejpeg($img); //显示灰色的方块
?>
㈨ PHP图像函数的请教GD库
move_uploaded_file() 函数将上传的文件移动到新位置。
注释:本函数仅用于通过 HTTP POST 上传的文件。
你使用imageresampled创建的文件不能使用move_uploaded_file()
建议使用fwrite写入。