最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2011年03月09日 22:47:49   作者:  
PHP用GD庫生成高質(zhì)量的縮略圖片,PHP一般情況下生成的縮略圖都比較不理想。今天試用PHP,GD庫來生成縮略圖。雖然并不100%完美??墒且矐?yīng)該可以滿足縮略圖的要求了。
以下是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);
}
}
?>

以下是測試代碼(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>

相關(guān)文章

最新評論

郓城县| 滁州市| 呼玛县| 呼图壁县| 手游| 家居| 栖霞市| 德兴市| 班玛县| 郓城县| 蕉岭县| 长子县| 蒙自县| 金湖县| 滨海县| 丰县| 成武县| 桂东县| 庆云县| 仪征市| 台安县| 山丹县| 庄浪县| 宁明县| 伊川县| 固安县| 长寿区| 黑河市| 扶绥县| 东港市| 保靖县| 务川| 百色市| 高清| 凭祥市| 山阳县| 东平县| 屏东市| 舞阳县| 霍城县| 乡宁县|