调用在这里:if (strlen($_FILES['pfile']['tmp_name'])>0 && $_FILES['pfile']['tmp_name'] != "none") {
$sname = $_FILES['pfile']['tmp_name'];
$preview_id = substr($_FILES['pfile']['name'],0,-4);
$preview_dir = "./img/small/".$preview_id;
// preview
if (!$maxsize)
$maxsize = 100;
$thumb=new makepic();
$thumb->thumbnail($sname,$_FILES['pfile']['type']);
$thumb->size_auto($maxsize);
$thumb->jpeg_quality(100);
$thumb->show();
}
$sname = $_FILES['pfile']['tmp_name'];
$preview_id = substr($_FILES['pfile']['name'],0,-4);
$preview_dir = "./img/small/".$preview_id;
// preview
if (!$maxsize)
$maxsize = 100;
$thumb=new makepic();
$thumb->thumbnail($sname,$_FILES['pfile']['type']);
$thumb->size_auto($maxsize);
$thumb->jpeg_quality(100);
$thumb->show();
}
比如:<img src=24.jpg border=0>
function size_height($size=100)
{
//height
$this->img["tinggi_thumb"]=$size;
@$this->img["lebar_thumb"] =ceil(($this->img["tinggi_thumb"]/$this->img["tinggi"])*$this->img["lebar"]);
} function size_width($size=100)
{
//width
$this->img["lebar_thumb"]=$size;
@$this->img["tinggi_thumb"] =ceil(($this->img["lebar_thumb"]/$this->img["lebar"])*$this->img["tinggi"]);
} function size_auto($size=100)
{
//size
if ($this->img["lebar"]>=$this->img["tinggi"]) {
$this->img["lebar_thumb"]=$size;
@$this->img["tinggi_thumb"] =ceil(($this->img["lebar_thumb"]/$this->img["lebar"])*$this->img["tinggi"]);
} else {
$this->img["tinggi_thumb"]=$size;
@$this->img["lebar_thumb"] =ceil(($this->img["tinggi_thumb"]/$this->img["tinggi"])*$this->img["lebar"]);
}
}
GD 2.0.l 或更高版本
imagecopyresized换成imagecopyresampled
图像质量也好点。
<?php
/*
* 图片缩略图
* $srcfile 源图片,$rate 缩放比,默认为缩小一半
* 例如: resizeimage("zt32.gif",".1");
*/
function resizeimage($srcfile,$rate=.5){
$size=getimagesize($srcfile);
switch($size[2]){
case 1:
$img=imagecreatefromgif($srcfile);
break;
case 2:
$img=imagecreatefromjpeg($srcfile);
break;
case 3:
$img=imagecreatefrompng($srcfile);
break;
}
//源图片的宽度和高度
$srcw=imagesx($img);
$srch=imagesy($img);
//目的图片的宽度和高度
$dstw=floor($srcw*$rate);
$dsth=floor($srch*$rate);
//新建一个真彩色图像
$im=imagecreatetruecolor($dstw,$dsth);
$black=imagecolorallocate($im,255,255,255);
imagefilledrectangle($im,0,0,$dstw,$dsth,$black);
imagecopyresized($im,$img,0,0,0,0,$dstw,$dsth,$srcw,$srch);
// 以 JPEG 格式将图像输出到浏览器或文件
header("content-type: image/jpeg");
imagejpeg($im);
//释放图片
imagedestroy($im);
imagedestroy($img);}
resizeimage("zt32.gif",".1");
?>
ImageCreateTrueColor to ImageCreate