function ResizeImage($im,$maxwidth,$maxh " /> 香蕉久久aⅴ一区二区三区,欧美日韩天天操,色欧美88888久久久久久影院

色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

PHP用GD庫(kù)生成高質(zhì)量的縮略圖片

以下是php源代碼(ResizeImage.php)。
復(fù)制代碼 代碼如下:
<?php
$FILENAME="image.thumb";
// 生成圖片的寬度
$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);
}
}
?>

以下是測(cè)試代碼(demo.php)
復(fù)制代碼 代碼如下:
<?php
include('ResizeImage.php');
if(!empty($_POST)){
echo($FILENAME.".jpg?cache=".rand(0,999999));
}
?>
<form name="test" action="?submit=true" enctype="multipart/form-data" method="post" >
<input type="file" name="image" size="50" value="瀏覽"><p>
<input type="submit" value="上傳圖片">
</form>

php技術(shù)PHP用GD庫(kù)生成高質(zhì)量的縮略圖片,轉(zhuǎn)載需保留來(lái)源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 仙居县| 大理市| 达日县| 遵义县| 锡林浩特市| 大荔县| 渑池县| 合肥市| 宜川县| 屯门区| 连城县| 贞丰县| 太原市| 兴山县| 泌阳县| 通江县| 凌云县| 灌南县| 涞源县| 昆明市| 东宁县| 区。| 贵定县| 新乐市| 陆丰市| 濉溪县| 华坪县| 乌兰县| 肃宁县| 莫力| 含山县| 宁德市| 崇仁县| 龙口市| 萍乡市| 亳州市| 石楼县| 永胜县| 衡阳市| 嘉黎县| 枣庄市|