仓酷云

标题: PHP编程:php 天生缩略图:PHP天生智能缩略图 [打印本页]

作者: 兰色精灵    时间: 2015-1-16 22:15
标题: PHP编程:php 天生缩略图:PHP天生智能缩略图
根据功能来进行封装等。很多的不懂,在使用搜索引擎查找,或者请教老师和在老师详细的讲解、指导下,都能顺利解决。
<?php
classresizeimage{
//图片范例
var$type;
//实践宽度
var$width;
//实践高度
var$height;
//改动后的宽度
var$resize_width;
//改动后的高度
var$resize_height;
//是不是裁图
var$cut;
//源图像
var$srcimg;
//方针图像地点
var$dstimg;
//一时创立的图像
var$im;
functionresizeimage($img,$wid,$hei,$c,$dstpath){
$this->srcimg=$img;
$this->resize_width=$wid;
$this->resize_height=$hei;
$this->cut=$c;
//图片的范例
$this->type=strtolower(substr(strrchr($this->srcimg,"."),1));
//初始化图像
$this->initi_img();
//方针图像地点
$this->dst_img($dstpath);
$this->width=imagesx($this->im);
$this->height=imagesy($this->im);
//天生图像
$this->newimg();
ImageDestroy($this->im);
}
functionnewimg(){
//改动后的图像的比例
$resize_ratio=($this->resize_width)/($this->resize_height);
//实践图像的比例
$ratio=($this->width)/($this->height);
if(($this->cut)=="1")//裁图
{
if($ratio>=$resize_ratio)//高度优先
{
$newimg=imagecreatetruecolor($this->resize_width,$this->resize_height);
imagecopyresampled($newimg,$this->im,0,0,0,0,$this->resize_width,$this->resize_height,(($this->height)*$resize_ratio),$this->height);
ImageJpeg($newimg,$this->dstimg);
}
if($ratio<$resize_ratio)//宽度优先
{
$newimg=imagecreatetruecolor($this->resize_width,$this->resize_height);
imagecopyresampled($newimg,$this->im,0,0,0,0,$this->resize_width,$this->resize_height,$this->width,(($this->width)/$resize_ratio));
ImageJpeg($newimg,$this->dstimg);
}
}else//不裁图
{
if($ratio>=$resize_ratio){
$newimg=imagecreatetruecolor($this->resize_width,($this->resize_width)/$ratio);
imagecopyresampled($newimg,$this->im,0,0,0,0,$this->resize_width,($this->resize_width)/$ratio,$this->width,$this->height);
ImageJpeg($newimg,$this->dstimg);
}
if($ratio<$resize_ratio){
$newimg=imagecreatetruecolor(($this->resize_height)*$ratio,$this->resize_height);
imagecopyresampled($newimg,$this->im,0,0,0,0,($this->resize_height)*$ratio,$this->resize_height,$this->width,$this->height);
ImageJpeg($newimg,$this->dstimg);
}
}
}
//初始化图像
functioniniti_img(){
if($this->type=="jpg"){
$this->im=imagecreatefromjpeg($this->srcimg);
}
if($this->type=="gif"){
$this->im=imagecreatefromgif($this->srcimg);
}
if($this->type=="png"){
$this->im=imagecreatefrompng($this->srcimg);
}
}
//图像方针地点
functiondst_img($dstpath){本文链接http://www.cxybl.com/html/wlbc/Php/20130326/37402.html从刚开始练习的PHP基础语法练习,到PHP语言在WEB中的应用,再到实际的项目开发,如留言版,相册系统,中小型公司网站系统,以及期间做过的有关团队合作的小游戏,让我受益匪浅,学到了很多。
作者: 精灵巫婆    时间: 2015-1-19 06:22
实践是检验自己会不会的真理。
作者: 冷月葬花魂    时间: 2015-1-27 07:34
写的比较杂,因为我也是个新手,不当至于大家多多指正。
作者: 小女巫    时间: 2015-2-5 04:47
在学习的过程中不能怕麻烦,不能有懒惰的思想。学习php首先应该搭建一个lamp环境或者是wamp环境。这是学习php开发的根本。虽然网络上有很多集成的环境,安装很方便,使用起来也很稳定、
作者: 乐观    时间: 2015-2-11 05:34
要进行开发,搭建环境是首先需要做的事,windows下面我习惯把环境那个安装在C盘下面,因为我配的环境经常出现诡异事件,什么事都没做环境有的时候就不能用啦。
作者: 柔情似水    时间: 2015-3-1 22:35
如果你已经到这种程度了,那么你已经可以做我的老师了。其实php也分很多的区域,
作者: 金色的骷髅    时间: 2015-3-11 01:07
当留言板完成的时候,下步可以把做1个单人的blog程序,做为目标,
作者: 分手快乐    时间: 2015-3-17 17:39
如果你可以写完像留言板这样的程序,那么你可以去一些别人的代码了,
作者: 深爱那片海    时间: 2015-3-24 17:28
首先我是坚决反对新手上来就用框架的,因为对底层的东西一点都不了解,造成知识上的真空,会对以后的发展不利。我的观点上手了解下框架就好,代码还是手写。当然啦如果是位别的编程语言的高手的话,这个就另当别论啦。




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