?php /* *生成缩略图 *$imgPath(图片路径), $maxWidth(宽), $maxHeight(高), $directOutput = true(是否在页面输出), $quality = 90, $verbose,$imageType(图片类型) * * */ function resizeImg($imgPath, $maxWidth, $maxHeight, $directOutput =
/*
*生成缩略图
*$imgPath(图片路径), $maxWidth(宽), $maxHeight(高), $directOutput = true(是否在页面输出), $quality = 90, $verbose,$imageType(图片类型)
*
*
*/
function resizeImg($imgPath, $maxWidth, $maxHeight, $directOutput = true, $quality = 90, $verbose,$imageType)
{
$size = getimagesize($imgPath);
//print_r($size);exit;
// break and return false if failed to read image infos
if(!$size){
if($verbose && !$directOutput)echo "
Not able to read image infos.
";
return false;
}
// relation: width/height
$relation = $size[0]/$size[1];
// maximal size (if parameter == false, no resizing will be made)
$maxSize = array($maxWidth?$maxWidth:$size[0],$maxHeight?$maxHeight:$size[1]);
// declaring array for new size (initial value = original size)
$newSize = $size;
// width/height relation
$relation = array($size[1]/$size[0], $size[0]/$size[1]);
//print_r($size);
//echo "
";
//print_r($relation);exit;
if(($newSize[0] > $maxWidth))
{
$newSize[0]=$maxSize[0];
$newSize[1]=$newSize[0]*$relation[0];
}
if(($newSize[1] > $maxHeight))
{
$newSize[1]=$maxSize[1];
$newSize[0]=$newSize[1]*$relation[1];
}
// create image
switch($size[2])
{
case 1:
if(function_exists("imagecreatefromgif"))
{
$originalImage = imagecreatefromgif($imgPath);
}else{
if($verbose && !$directOutput)echo "
No GIF support in this php installation, sorry.
";
return false;
}
break;
case 2: $originalImage = imagecreatefromjpeg($imgPath); break;
case 3: $originalImage = imagecreatefrompng($imgPath); break;
default:
if($verbose && !$directOutput)echo "
No valid image type.
";
return false;
}
// create new image
$resizedImage = imagecreatetruecolor($newSize[0], $newSize[1]);
imagecopyresampled($resizedImage, $originalImage,0, 0, 0, 0,$newSize[0], $newSize[1], $size[0], $size[1]);
$rz=$imgPath;
// output or save
if($directOutput)
{
imagejpeg($resizedImage);
}
else
{
$exp=explode(".",$imgPath);
$extension=end($exp);//$exp[count($exp)-1];
$newimage=$imageType.".".$extension;
$rz=preg_replace("//.([a-zA-Z]{3,4})$/",$newimage,$imgPath);
imagejpeg($resizedImage, $rz, $quality);
}
// return true if successfull
return $rz;
} // End function Resize Image
//调用
resizeImg("var/chen.jpg", 125 ,75, false, 100, 0,"_thumb");
?>

ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

PhpStorm Mac バージョン
最新(2018.2.1)のプロフェッショナル向けPHP統合開発ツール

AtomエディタMac版ダウンロード
最も人気のあるオープンソースエディター

WebStorm Mac版
便利なJavaScript開発ツール

SecLists
SecLists は、セキュリティ テスターの究極の相棒です。これは、セキュリティ評価中に頻繁に使用されるさまざまな種類のリストを 1 か所にまとめたものです。 SecLists は、セキュリティ テスターが必要とする可能性のあるすべてのリストを便利に提供することで、セキュリティ テストをより効率的かつ生産的にするのに役立ちます。リストの種類には、ユーザー名、パスワード、URL、ファジング ペイロード、機密データ パターン、Web シェルなどが含まれます。テスターはこのリポジトリを新しいテスト マシンにプルするだけで、必要なあらゆる種類のリストにアクセスできるようになります。

EditPlus 中国語クラック版
サイズが小さく、構文の強調表示、コード プロンプト機能はサポートされていません

ホットトピック









