验证码、水印、缩放

随机生成验证码

1、验证码
1、纯数字
2、纯字母
3、数字字母混合
4、计算公式 3 + 5 =
打乱字符串:str_shuffle
提取子串:substr
产生一个0-9的数组:range(0, 9)
打乱数组:shuffle
数组合并:array_merge()
数组键值对调:array_flip
数组中提取子数组:array_slice
数组中元素执行回调函数:array_map
数字转化为ascii:chr ord
不区分大小写字符串比较:strcasecmp
2、水印

3、缩放

思考:
这个switch case是否可以优化?

function kidOfImage($srcImg, $size, $imgInfo){
//传入新的尺寸,创建一个指定尺寸的图片
$newImg = imagecreatetruecolor($size['old_w'], $size['old_h']);
//定义透明色
$otsc = imagecolortransparent($srcImg);
if( $otsc >= 0) {
//取得透明色
$transparentcolor = imagecolorsforindex( $srcImg, $otsc );
//创建透明色
$newtransparentcolor = imagecolorallocate(
$newImg,
$transparentcolor['red'],
$transparentcolor['green'],
$transparentcolor['blue']
);
} else {
$newtransparentcolor = imagecolorallocate($newImg, 0, 0, 0);
}
//背景填充透明
imagefill( $newImg, 0, 0, $newtransparentcolor );
imagecolortransparent($newImg, $newtransparentcolor);

imagecopyresized( $newImg, $srcImg, $size['x'], $size['y'], 0, 0, $size["new_w"], $size["new_h"], $imgInfo["width"], $imgInfo["height"] );
return $newImg;

}

你可能感兴趣的:(验证码、水印、缩放)