您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

非常简单PHP缩略图生成程序源代码_PHP

2024/4/1 1:10:37发布27次查看
一个非常简单的php生成缩略图的代码程序,参数及代码都算得上精简,有兴趣的朋友可以试下它的功能,有不太完善的地方还请指正。
$filename=image_name;
// 生成图片的宽度
$resizewidth=400;
// 生成图片的高度
$resizeheight=400;
function resizeimage($im,$maxwidth,$maxheight,$name){
$width = imagesx($im);
$height = imagesy($im);
if(($maxwidth && $width > $maxwidth) || ($maxheight && $height > $maxheight)){
if($maxwidth && $width > $maxwidth){
$widthratio = $maxwidth/$width;
$resizewidth=true;
}
if($maxheight && $height > $maxheight){
$heightratio = $maxheight/$height;
$resizeheight=true;
}
if($resizewidth && $resizeheight){
if($widthratio $ratio = $widthratio;
}else{
$ratio = $heightratio;
}
}elseif($resizewidth){
$ratio = $widthratio;
}elseif($resizeheight){
$ratio = $heightratio;
}
$newwidth = $width * $ratio;
$newheight = $height * $ratio;
if(function_exists(imagecopyresampled)){
$newim = imagecreatetruecolor($newwidth, $newheight);
imagecopyresampled($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}else{
$newim = imagecreate($newwidth, $newheight);
imagecopyresized($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}
imagejpeg ($newim,$name . .jpg);
imagedestroy ($newim);
}else{
imagejpeg ($im,$name . .jpg);
}
}
if($_files['image']['size']){
if($_files['image']['type'] == image/pjpeg){
$im = imagecreatefromjpeg($_files['image']['tmp_name']);
}elseif($_files['image']['type'] == image/x-png){
$im = imagecreatefrompng($_files['image']['tmp_name']);
}elseif($_files['image']['type'] == image/gif){
$im = imagecreatefromgif($_files['image']['tmp_name']);
}
if($im){
if(file_exists($filename.jpg)){
unlink($filename.jpg);
}
resizeimage($im,$resizewidth,$resizeheight,$filename); www~phperz~com
imagedestroy ($im);
}
}
?>
>
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product