水印,缩放裁剪,文件和目录。
水印
补充了一点昨天那些相关函数的部分说明,不过相关补充写入了昨天的日志里,内容分割开的话可能队以后的阅读造成影响,故不单独列出来了。
文字水印
<?php header('Content-type:image/jpeg'); $img = imagecreatefromjpeg('/phpstudy_pro/WWW/51CTO_Study/D01/Verification_Code/images/c01.jpg'); $color6 = imagecolorallocate($img, 200, 200, 200);
$width = imagesx($img); $height = imagesy($img);
$fontfile = "Captcha_module/font/CangJiGaoDeGuoMiaoHei/CangJiGaoDeGuoMiaoHei-CJgaodeguomh-2.ttf"; $str_all = "CSDN@SYW_SEC";
$str_array = imagettfbbox(15, 0, $fontfile, "CSDN@SYW_SEC"); $strw = abs($str_array[0] - $str_array[2]); $strh = abs($str_array[3] - $str_array[5]);
imagettftext($img, 15, 0, ($width - $strw - 10), ($height - $strh), $color6, $fontfile, $str_all);
imagejpeg($img); imagedestroy($img);
|

图片水印
<?php header('Content-type:image/jpeg');
$img = imagecreatefromjpeg("Verification_Code/images/c01.jpg"); $color1 = imagecolorallocate($img, 200, 200, 200);
$water = imagecreatefrompng("Verification_Code/images/CSDN_LOGO.png");
$imgw = imagesx($img); $imgh = imagesy($img);
$waterw = imagesx($water); $waterh = imagesy($water);
imagecopy($img, $water, $imgw - $waterw, $imgh - $waterh, 0, 0, $waterw, $waterh);
imagejpeg($img); imagedestroy($img);
|


截取与缩放
截取
<?php header('Content-type:image/jpeg'); $simg = imagecreatefrompng('images/w2.png'); $eimg = imagecreatetruecolor(500, 500);
imagecopyresampled($eimg, $simg, 100, 100, 0, 0, 200, 200, 200, 200);
imagejpeg($eimg);
imagedestroy($simg); imagedestroy($eimg);
|

缩略
这种类型的缩放会比原图占用的资源更少。 尺寸变小 ,占用的 容量 也 变小 。
<?php header('Content-type:image/jpeg');
$width = 100;
$simg = imagecreatefrompng('images/w2.png');
$simgw = imagesx($simg); $simgh = imagesy($simg);
$height = $width / ($simgw / $simgh);
$eimg = imagecreatetruecolor($width, $height);
imagecopyresampled($eimg, $simg, 0, 0, 0, 0, $width, $height, $simgw, $simgh);
imagejpeg($eimg);
imagedestroy($eimg);
|

文件和目录
返回的值是布尔值,是则返回true,否则返回false 判断是文件:is_file('文件名或者路径文件名'); 判断是目录:is_dir('路径或者路径文件目录');
|
判断普通文件和目录
文件属性
is_readable() is_writable() filectime() filemtime() fileatime() stat()
|
目录基本操作
__FILE__:返回当前文件名路径
1.basename(); 2.dirname(); 3.pathinfo();
4.opendir(); 5.readdir();
6.rewinddir();
7.closedir();
8.mkdir('name',权限,bool); 9.rmdir(); 10.scandir();
|
文件基本操作
1.fopen()
2.fread()
3.fgets()
4.feof()
5.fwrite()
6.rewind()
7.flock()
8.ftruncate()
9.fclose()
10.file()
11.copy()
12.unlink() 13.file_get_contents()
14.file_put_contents()
15.rename()
16.readfile() int readfile(string $filename, bool $use_include_path = false, resource $context = null);
|