最简单的上传php文件 php多图上传插件( 四 )


$size[“height”]=round($imgInfo[“height”]*$size[“width”]/$imgInfo[“width”]);
}else{
$size[“width”]=round($imgInfo[“width”]*$size[“height”]/$imgInfo[“height”]);
}
return $size;
}
private function getInfo($name){
$data=https://www.520longzhigu.com/diannao/getImageSize($this->path.$name);
$imageInfo[“width”]=$data[0];
$imageInfo[“height”]=$data[1];
$imageInfo[“type”]=$data[2];
return $imageInfo;
}
private function getImg($name, $imgInfo){
$srcPic=$this->path.$name;
switch($imgInfo[“type”]){
case 1: //gif
$img=imagecreatefromgif($srcPic);
break;
case 2: //jpg
$img=imageCreatefromjpeg($srcPic);
break;
case 3: //png
$img=imageCreatefrompng($srcPic);
break;
default:
return false;
}
return $img;
}
/* 功能:为图片加水印图片
* 参数$groundName: 背景图片,即需要加水印的图片
* 参数$waterName: 水钱图片
* 参数#aterPost:水印位置,10种状态,
* 0为随机位置
*
* 1. 为顶端居左 2. 为顶端居中 3 为顶端居右
* 4 为中部居左 5. 为中部居中 6 为中部居右
* 7 . 为底端居左 8. 为底端居中,9. 为底端居右
*
* 参数$qz : 是加水印后的图片名称前缀
* 返回值:就是处理后图片的名称
*
*/
function waterMark($groundName, $waterName, $waterPos=0, $qz=”wa_”){
if(file_exists($this->path.$groundName) && file_exists($this->path.$waterName)){
$groundInfo=$this->getInfo($groundName);
$waterInfo=$this->getInfo($waterName);
//水印的位置
if(!$pos=$this->position($groundInfo, $waterInfo, $waterPos)){
echo “水印不应该比背景图片小!”;
return;
}
$groundImg=$this->getImg($groundName, $groundInfo);
$waterImg=$this->getImg($waterName, $waterInfo);
$groundImg=$this->copyImage($groundImg, $waterImg, $pos, $waterInfo);
return $this->createNewImage($groundImg, $qz.$groundName, $groundInfo);
}else{
echo “图片或水印图片不存在”;
return false;
}
}
private function copyImage($groundImg, $waterImg, $pos, $waterInfo){
imagecopy($groundImg, $waterImg, $pos[“posX”], $pos[“posY”], 0, 0, $waterInfo[“width”], $waterInfo[“height”]);
imagedestroy($waterImg);
return $groundImg;
}
private function position($groundInfo, $waterInfo, $waterPos){
//需要背景比水印图片大
if(($groundInfo[“width”]< $waterInfo[“width”]) ||($groundInfo[“height”] < $waterInfo[“height”])){
return false;
}
switch($waterPos){
case 1:
$posX=0;
$posY=0;
break;
case 2:
$posX=($groundInfo[“width”]-$waterInfo[“width”])/2;
$posY=0;
break;
case 3:
$posX=$groundInfo[“width”]-$waterInfo[“width”];
$posY=0;
break;
case 4:
$posX=0;
$posY=($groundInfo[“height”]-$waterInfo[“height”]) /2;
break;
case 5:
$posX=($groundInfo[“width”]-$waterInfo[“width”])/2;
$posY=($groundInfo[“height”]-$waterInfo[“height”]) /2;
break;
case 6:
$posX=$groundInfo[“width”]-$waterInfo[“width”];
$posY=($groundInfo[“height”]-$waterInfo[“height”]) /2;
break;
case 7:
$posX=0;
$posY=$groundInfo[“height”]-$waterInfo[“height”];
break;


以上关于本文的内容,仅作参考!温馨提示:如遇健康、疾病相关的问题,请您及时就医或请专业人士给予相关指导!

「四川龙网」www.sichuanlong.com小编还为您精选了以下内容,希望对您有所帮助: