欢迎光临
我们一直在努力

PHP缩略图生成程序-PHP教程,PHP技巧

建站超值云服务器,限时71元/月

<?

$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 < $heightratio){

$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);

imagedestroy ($im);

}

}

?>

<img src="<? echo($filename.".jpg?reload=".rand(0,999999)); ?>"><br><br>

<form enctype="multipart/form-data" method="post">

<br>

<input type="file" name="image" size="50" value="浏览"><p>

<input type="submit" value="上传图片">

</form>

</body>

</html>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » PHP缩略图生成程序-PHP教程,PHP技巧
分享到: 更多 (0)