PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

php gd搴撳嚱鏁扮敓鎴愰珮娓呯缉鐣ュ浘绋嬪簭_PHP鏁欑▼ | 甯涔嬪

原创
2016-07-13 10:45:56 960浏览

gd搴撴槸php鏁欑▼涓竴涓鐞嗗浘鍍忕殑涓撶敤搴擄紝浠栧彲浠ユ柟渚垮揩鎹风殑澶勭悊澶у鏁版嵁澶勭悊锛屽畠鎻愪緵浜嗗ぇ閲忕殑鍥剧墖澶勭悊鍑芥暟锛屼笅闈㈡垜浠氨鍒╃敤gd搴撶殑鍑芥暟鏉ョ敓鎴愮缉鐣ュ浘銆?br /> 娴嬭瘯浠g爜

 

include('resizeimage.php');
if(!empty($_post)){
echo($filename.".jpg?cache=".rand(0,999999));
}
?>



resizeimage.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 $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);
}
}
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/632985.htmlTechArticlegd搴撴槸php鏁欑▼涓竴涓鐞嗗浘鍍忕殑涓撶敤搴擄紝浠栧彲浠ユ柟渚垮揩鎹风殑澶勭悊澶у鏁版嵁澶勭悊锛屽畠鎻愪緵浜嗗ぇ閲忕殑鍥剧墖澶勭悊鍑芥暟锛屼笅闈㈡垜浠氨鍒╃敤gd搴撶殑鍑芥暟鏉?..
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。