当前位置:Linux教程 - Php - 怎么在一个图片上打上标签

怎么在一个图片上打上标签

<?php
header
("Content-type: image/jpeg");
$img1="happy.png";
$img2="126.jpg";
$strhh = GetImageSize("$img2");
$strw = GetImageSize("$img1");
$strh = GetImageSize("$img1");
$titleWidth = $strw[0];
$titleHeight = $strh[1];
$strhh = $strhh[1]-$titleHeight-5;
$newImg = ImageCreateFromjpeg("$img2");
$origImg = ImageCreateFrompng("$img1");
ImageCopyResized($newImg,$origImg,5,$strhh,0,0,$titleWidth,$titleHeight,ImageSX($origImg),ImageSY($origImg));
Imagejpeg($newImg);
ImageDestroy($newImg);
?>



搞定了。 代码拿出来大家分享一下。


PHP代码:--------------------------------------------------------------------------------

<?php
if($_FILES['upf']['size']>100000){
    echo
"你的图片文件太大了。请选择较小的图片.<br><a href=upform.htm>返回</a>";
    exit();
}
if(
strrchr($_FILES['upf']['name'],".")==".jpg" or strrchr($_FILES['upf']['name'],".")==".jpeg"){
    
header("Content-type: image/jpeg");
    
$img1="1.png";
    
$img2=$_FILES[upf][tmp_name];
    
$strhh = GetImageSize("$img2");
    
$strw = GetImageSize("$img1");
    
$strh = GetImageSize("$img1");
    
$titleWidth = $strw[0];
    
$titleHeight = $strh[1];
    
$strhh = $strhh[1]-$titleHeight-5;
    
$newImg = ImageCreateFromjpeg("$img2");
    
$origImg = ImageCreateFrompng("$img1");
    
ImageCopyResized($newImg,$origImg,5,$strhh,0,0,$titleWidth,$titleHeight,ImageSX($origImg),ImageSY($origImg));
    
$upfname = "/upimg/2004/".date("ymdhis",time()).".jpg";
    
Imagejpeg($newImg,$_SERVER['DOCUMENT_ROOT'].$upfname);
    
ImageDestroy($newImg);
    echo
"<img src='".$upfname."'><br><br> 上传后URL:<input name='a' style='width=500' type='text' value='http://www.ta-it.com".$upfname."' onMouseOver='this.select()'>";
    
}else if(
strrchr($_FILES['upf']['name'],".")==".gif"){
    
header("Content-type: image/jpeg");
    
$img1="1.png";
    
$img2=$_FILES[upf][tmp_name];
    
$strhh = GetImageSize("$img2");
    
$strw = GetImageSize("$img1");
    
$strh = GetImageSize("$img1");
    
$titleWidth = $strw[0];
    
$titleHeight = $strh[1];
    
$strhh = $strhh[1]-$titleHeight-5;
    
$newImg = ImageCreateFromgif("$img2");
    
$origImg = ImageCreateFrompng("$img1");
    
ImageCopyResized($newImg,$origImg,5,$strhh,0,0,$titleWidth,$titleHeight,ImageSX($origImg),ImageSY($origImg));
    
$upfname = "/upimg/2004/".date("ymdhis",time()).".jpg";
    
Imagejpeg($newImg,$_SERVER['DOCUMENT_ROOT'].$upfname);
    
ImageDestroy($newImg);
    echo
"<img src='".$upfname."'><br><br> 上传后URL:<input name='a' style='width=500' type='text' value='http://www.ta-it.com".$upfname."' onMouseOver='this.select()'>";
    
}else if(
strrchr($_FILES['upf']['name'],".")==".bmp"){
$upfname = "/upimg/2004/".date("ymdhis",time()).strrchr($_FILES['upf']['name'],".");
copy($_FILES['upf']['tmp_name'],$_SERVER['DOCUMENT_ROOT'].$upfname);
echo
"<img src='".$upfname."'><br><br> 上传后URL:<input name='a' style='width=500' type='text' value='http://www.ta-it.com".$upfname."' onMouseOver='this.select()'>";
}else{
    echo
"目前只支持:.jpg .jpeg .gif .bmp图片格式";
}
?>
<p><br>
  <a href="upform.htm">返回</a></p>
--------------------------------------------------------------------------------



__________________