生成缩略图
$tx=getimagesize($sample);
if($tx[0]<=$tx[1] and $tx[1]>=120){
$height=120;
$width=intval($height*$tx[0]/$tx[1]);
}
if($tx[0]>=$tx[1] and $tx[0]>=100){
$width=100;
$height=intval($width*$tx[1]/$tx[0]);
}
if($tx[0]<100 and $tx[1]<120){
$width=$tx[0];
$height=$tx[1];
}
makethumb2($sample,$target,$width,$height);
// $srcfile: 源文件
// $dstfile: 目标文件
// $dstw: 目标图片宽度
// $dsth: 目标文件高度
function makethumb2($srcfile,$dstfile,$dstw,$dsth){
$data=getimagesize($srcfile,&$info);
switch($data[2]){
case 1:
$im=@imagecreatefromgif($srcfile);
break;
case 2:
$im=@imagecreatefromjpeg($srcfile);
break;
case 3:
$im=@imagecreatefrompng($srcfile);
break;
}
$srcw=imagesx($im);
$srch=imagesy($im);
$ni=imagecreate($dstw,$dsth);
imagecopyresized($ni,$im,0,0,0,0,$dstw,$dsth,$srcw,$srch);
imagejpeg($ni,$dstfile);
// 如果需要输出到浏览器,那么将上一句改为imagejpeg($ni);
// 如果需要其它格式的图片,改动最后一句就可以了
}
如对本文有疑问,
点击进行留言回复!!
相关文章:
-
-
-
-
网安追踪流程
1.不用代理网民发帖流程:发帖人 → ISP → 服务器托管商 → 服务器网警追踪流程:网监 → 服务器IP →...
[阅读全文]
-
-
-
HTTP状态码大全
转自:https://www.cnblogs.com/lxinxuan/archive/2009/10/22/1...
[阅读全文]
-
-
-
-
网友评论