仓酷云

标题: PHP编程:《PHP编程最快分明》第七讲:php图片验... [打印本页]

作者: 飘灵儿    时间: 2015-2-3 23:41
标题: PHP编程:《PHP编程最快分明》第七讲:php图片验...
在相册系统的开发上,因为采用的是团队分工合作方式,更让我明白了在一个团队之中,团队成员之间的交流沟通的重要性,如果没有很好的沟通交流,成员之间的任务没有分配好。   实例22 图片验证的中心代码
复制代码 代码以下:
<?php
//header("content-type:image/png");
$num ='1234';
$imagewidth=60;
$imageheight=18;

$numimage = imagecreate($imagewidth,$imageheight);
imagecolorallocate($numimage,240,240,240);
for($i=0;$i<strlen($num);$i++){
$x = mt_rand(1,8)+$imagewidth*$i/4;
$y = mt_rand(1,$imageheight/4);
$color=imagecolorallocate($numimage,mt_rand(0,150),mt_rand(0,150),mt_rand(0,150));
imagestring($numimage,5,$x,$y,$num[$i],$color);
}

for($i=0;$i<200;$i++){
$randcolor=imagecolorallocate($numimage,rand(200,255),rand(200,255),rand(200,255));
imagesetpixel($numimage,rand()%70,rand()%20,$randcolor);
}
imagepng($numimage);
imagedestroy($numimage);
?>

这个是输入4个验证码的例子,关于汉字,需求font文件和imagettftext函数,用到的时分人人再网上搜刮吧。你要发生随机数,那有mt_rand函数;你还要用到session保留这个随机数;假如需求转成utf-8,需求iconv函数。

实例23 缩略图
复制代码 代码以下:
<?php
class SimpleImage {
var $image;
var $image_type;
function load($filename) {
$image_info = getimagesize($filename);
$this->image_type = $image_info[2];
if( $this->image_type == IMAGETYPE_JPEG ) {
$this->image = imagecreatefromjpeg($filename);
} elseif( $this->image_type == IMAGETYPE_GIF ) {
$this->image = imagecreatefromgif($filename);
} elseif( $this->image_type == IMAGETYPE_PNG ) {
$this->image = imagecreatefrompng($filename);
}
}
function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) {
if( $image_type == IMAGETYPE_JPEG ) {
imagejpeg($this->image,$filename,$compression);
} elseif( $image_type == IMAGETYPE_GIF ) {
imagegif($this->image,$filename);
} elseif( $image_type == IMAGETYPE_PNG ) {
imagepng($this->image,$filename);
}
if( $permissions != null) {
chmod($filename,$permissions);
}
}
function output($image_type=IMAGETYPE_JPEG) {
if( $image_type == IMAGETYPE_JPEG ) {
imagejpeg($this->image);
} elseif( $image_type == IMAGETYPE_GIF ) {
imagegif($this->image);
} elseif( $image_type == IMAGETYPE_PNG ) {
imagepng($this->image);
}
}
function getWidth() {
return imagesx($this->image);
}
function getHeight() {
return imagesy($this->image);
}
function resizeToHeight($height) {
$ratio = $height / $this->getHeight();
$width = $this->getWidth() * $ratio;
$this->resize($width,$height);
}
function resizeToWidth($width) {
$ratio = $width / $this->getWidth();
$height = $this->getheight() * $ratio;
$this->resize($width,$height);
}
function scale($scale) {
$width = $this->getWidth() * $scale/100;
$height = $this->getheight() * $scale/100;
$this->resize($width,$height);
}
function resize($width,$height) {
$new_image = imagecreatetruecolor($width, $height);
imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
$this->image = $new_image;
}
}

$newfile = UPLOAD_DIR."/icons/".md5($_SESSION['USER']->email).".jpg";//上传文件保留的目次
$image = new SimpleImage();
$image->load($_FILES['icons']['tmp_name']);//上传的一时文件名
$image->resizeToWidth(80);设置宽度
$image->save($newfile);
?>
应该大致熟悉了一些学习过程,也许我的过程和你的有些出路,但是不管怎么样是殊途同归,我写这么多,也只是给大家一个借鉴的机会,至于好与不好,默默不敢打包票^0^
作者: 爱飞    时间: 2015-2-4 06:02
对于懒惰的朋友,我推荐php的集成环境xampp或者是wamp。这两个软件安装方便,使用简单。但是我还是强烈建议自己动手搭建开发环境。
作者: 愤怒的大鸟    时间: 2015-2-4 13:23
Ps:以上纯属原创,如有雷同,纯属巧合
作者: 分手快乐    时间: 2015-2-9 23:25
因为blog这样的可以让你接触更多要学的知识,可以接触用到类,模板,js ,ajax
作者: 仓酷云    时间: 2015-2-28 05:01
有位前辈曾经跟我说过,phper 至少要掌握200个函数 编起程序来才能顺畅点,那些不熟悉的函数记不住也要一拿手册就能找到。所以建议新手们没事就看看php的手册(至少array函数和string函数是要记牢的)。
作者: 再现理想    时间: 2015-3-4 20:37
环境搭建好,当你看见你的浏览器输出“it works\\\\\\\"时你一定是喜悦的。在你解决问题的时候,我强烈建议多读php手册。
作者: 第二个灵魂    时间: 2015-3-11 20:56
不禁又想起那些说php是草根语言的人,为什么认得差距这么大呢。
作者: 飘飘悠悠    时间: 2015-3-19 13:16
其实没啥难的,多练习,练习写程序,真正的实践比看100遍都有用。不过要熟悉引擎
作者: 因胸联盟    时间: 2015-3-21 06:26
爱上php,他也会爱上你。
作者: 不帅    时间: 2015-4-3 21:16
建议加几个专业的phper的群,当然啦需要说话的人多,一处一点问题能有人回答你的,当然啦要让人回答你的问题,平时就得躲在里面聊天,大家混熟啦,愿意回答你问题的人自然就多啦。
作者: 若相依    时间: 2015-4-12 22:00
不禁又想起那些说php是草根语言的人,为什么认得差距这么大呢。
作者: 乐观    时间: 2015-4-13 03:13
说点我烦的低级错误吧,曾经有次插入mysql的时间 弄了300年结果老报错,其实mysql的时间是有限制的,大概是到203X年  具体的记不清啦,囧。
作者: 海妖    时间: 2015-4-16 07:11
说点我烦的低级错误吧,曾经有次插入mysql的时间 弄了300年结果老报错,其实mysql的时间是有限制的,大概是到203X年  具体的记不清啦,囧。
作者: 小魔女    时间: 2015-4-28 03:01
这些中手常用的知识,当你把我说的这些关键字都可以熟练运用的时候,你可以选择自己
作者: 蒙在股里    时间: 2015-5-6 09:11
先学习php和mysql,还有css(html语言很简单)我认为现在的效果比以前的方法好。
作者: 金色的骷髅    时间: 2015-5-6 18:16
有位前辈曾经跟我说过,phper 至少要掌握200个函数 编起程序来才能顺畅点,那些不熟悉的函数记不住也要一拿手册就能找到。所以建议新手们没事就看看php的手册(至少array函数和string函数是要记牢的)。
作者: 透明    时间: 2015-5-12 10:27
我学习了一段时间后,我发现效果并不好(估计是我自身的问题)。因为一个人的精力总是有限的,同时学习这么多,会导致每个的学习时间都得不到保证。
作者: 只想知道    时间: 2015-6-26 21:37
先学习php和mysql,还有css(html语言很简单)我认为现在的效果比以前的方法好。
作者: 老尸    时间: 2015-7-11 08:53
,熟悉html,能用div+css,还有javascript,优先考虑linux。我在开始学习的时候,就想把这些知识一起学习,我天真的认为同时学习能够互相呼应,因为知识是相通的。
作者: 变相怪杰    时间: 2015-7-14 18:56
做为1门年轻的语言,php一直很努力。
作者: 精灵巫婆    时间: 2015-7-28 05:31
Apache不是非得用80或者8080端口的,我刚开始安得时候就是80端口老占用,就用了个 81端口,结果照常,就是输localhost的时候,应该输入为 localhost:81




欢迎光临 仓酷云 (http://www.ckuyun.com/) Powered by Discuz! X3.2