function ResizeImage($im,$maxwidth,$maxh " /> 7777精品伊久久久大香线蕉语言,丁香花在线影院,欧美国产日产韩国视频

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

PHP用GD庫生成高質量的縮略圖片

以下是php源代碼(ResizeImage.php)。
復制代碼 代碼如下:
<?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)
復制代碼 代碼如下:
<?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技術PHP用GD庫生成高質量的縮略圖片,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 鲁山县| 光泽县| 德安县| 司法| 普宁市| 五原县| 昌图县| 绥棱县| 舒兰市| 克拉玛依市| 个旧市| 水城县| 清新县| 汾西县| 自贡市| 黔东| 安塞县| 元氏县| 台安县| 湘潭县| 沧源| 微博| 措勤县| 时尚| 游戏| 昆明市| 临武县| 岳阳市| 中牟县| 舒城县| 喀喇沁旗| 潢川县| 木里| 河东区| 霍山县| 孝感市| 南涧| 乌苏市| 辉南县| 内黄县| 霞浦县|