yzms/show/include/pic.php

35 lines
778 B
PHP
Raw Normal View History

2024-04-01 15:54:27 +08:00
<?
/*
$imgPath ԴͼƬ·<EFBFBD><EFBFBD>
$maxWidth <EFBFBD><EFBFBD>С<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
$maxHeight <EFBFBD><EFBFBD>С<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߶<EFBFBD>
$destPath Ŀ<EFBFBD><EFBFBD>·<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
function resizeImg($imgPath, $maxWidth, $maxHeight, $destPath = '') {
$img = imagecreatefromjpeg($imgPath);
$w = $w_o = imagesx($img);
$h = $h_o = imagesy($img);
if($w > $maxWidth) {
$h = intval($h*$maxWidth/$w);
$w = $maxWidth;
}
if($h > $maxHeight) {
$w = intval($w*$maxHeight/$h);
$h = $maxHeight;
}
//echo $w.",".$h;exit;
$img2 = imagecreatetruecolor($w, $h);
imagecopyresampled($img2, $img, 0, 0, 0, 0, $w, $h, $w_o, $h_o);
if($destPath) {
imagejpeg($img2, $destPath, 80);
} else {
header("Content-Type:image/jpeg");
imagejpeg($img2, '', 80);
}
imagedestroy($img2);
imagedestroy($img);
}
//resizeImg("1.jpg", 300, 300);