Chinaunix首页 | 论坛 | 博客
  • 博客访问: 159544
  • 博文数量: 19
  • 博客积分: 470
  • 博客等级: 下士
  • 技术积分: 252
  • 用 户 组: 普通用户
  • 注册时间: 2012-03-06 09:16
文章分类

全部博文(19)

文章存档

2013年(2)

2012年(17)

分类: WINDOWS

2012-06-14 15:24:32

点击(此处)折叠或打开

  1. <?php

  2. if (! session_id ()) {
  3.     session_start ();
  4. }

  5.     function getFile($dir) {
  6.         $fileArray[]=NULL;
  7.         if (false != ($handle = opendir ( $dir ))) {
  8.             $i=0;
  9.             while ( false !== ($file = readdir ( $handle )) ) {
  10.                 //去掉"“.”、“..”以及带“.xxx”后缀的文件
  11.                 if ($file != "." && $file != ".."&&strpos($file,".")) {
  12.                     
  13.                     $fileArray[$i]="./imageroot/current/".$file;
  14.                     
  15.                     if($i==100){
  16.                         break;
  17.                     }
  18.                     $i++;
  19.                 }
  20.             }
  21.             //关闭句柄
  22.             closedir ( $handle );
  23.         }
  24.         return $fileArray;
  25.     }
  26.     $url="";
  27.     if(!empty($_SESSION['url'])){
  28.         $url=$_SESSION['url'];
  29.     }else{
  30.         $urls=getFile("imageroot/current");
  31.         if(count($urls)==1){
  32.             echo "<script>alert('所有图片修改完成');</script>";
  33.             echo "<script>window.close;</script>";
  34.         }else if(count($urls)==2){
  35.             $url=$urls[0];
  36.         }else{
  37.             $url=$urls[rand(1,count($urls))-1];
  38.         }
  39.     }
  40.     
  41. ?>
  42. -//W3C//DTD XHTML 1.0 Strict//EN"
  43.   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  44. //www.w3.org/1999/xhtml">
  45.     
  46.         Content-type" content="text/html;charset=GB2312" />
  47.         截图工具
  48.         
  49.         
  50.         " href="css/jquery.Jcrop.css" type="text/css" />
  51.         " href="css/imgtool.css" type="text/css" />
  52.         
  53.     
  54.     
  55.     
    ">
  56.     
    ">
  57.     
    " >
  58.         <?=$url ?>" alt="target" id="target" onload="javascript:DrawImage(this,500,450);"/>
  59.         
  60.         
    coords" class="coords" action="imgresize.php" method="get" onsubmit="return check();">
  61.     

  62.              
  63.                 
  64.                 
  65.                 
  66.                 
  67.                 
  68.                 
  69.                 
  70.                 " size="10" id="src" name="src" value="<?=$url ?>" />
  71.                 

  72.                    
  73.                    
  74.             
  75.                 " value="保存" style="height:50px; width:200px; font-size:24px; background-color:green;border:green thin solid;cursor:pointer;
imgresize.php

点击(此处)折叠或打开

  1. <?php

  2. /**
  3.  * Goofy 2011-11-29
  4.  * 图像处理:根据传递过来的坐标参数,x,y,w,h,依次为选取的x坐标,y坐标,w宽度,h高度
  5.  * 通过imagecopy()方法将该区域copy至第一步创建的空白图像中
  6.  * 注意,在创建图像的时候要用imagecreatetruecolor()真彩色,不然用imagecreate()图片会失真
  7.  */

  8. if (! session_id ()) {
  9.     session_start ();
  10. }

  11. //页面传过来的比例
  12. $scale=$_GET['scale'];
  13. //下面的属性乘以相应的比例
  14. $x=$_GET['x']*$scale;
  15. $y=$_GET['y']*$scale;
  16. $w=$_GET['w']*$scale;
  17. $h=$_GET['h']*$scale;

  18. //源路径
  19. $src=$_GET['src'];

  20. //是否继续?如果不继续在这张图片截图,会将源图片删除
  21. $again="off";
  22. if(!empty($_GET['again'])){
  23.     $again=$_GET['again'];
  24. }
  25. echo $again;
  26. //第一步,根据传来的宽,高参数创建一幅图片,然后正好将截取的部分真好填充到这个区域
  27. header("Content-type: image/jpeg");
  28. $target = @imagecreatetruecolor($w,$h)
  29.     or die("Cannot Initialize new GD image stream");

  30. //第二步,根据路径获取到源图像,用源图像创建一个image对象
  31. $source = imagecreatefromjpeg($src);

  32. //第三步,根据传来的参数,选取源图像的一部分填充到第一步创建的图像中
  33. imagecopy( $target, $source, 0, 0, $x, $y, $w, $h);

  34. //第四步,保存图像
  35.     //截取并组织新路径
  36. $pos_path= strripos($src, "/");
  37. $newPath=substr($src,0,$pos_path-strlen($src))."_new/";
  38.     //截取并组织新名称
  39. $pos_name=strripos($src, ".");
  40. $newName=substr($src,0,$pos_name);
  41. $pos_name_= strripos($newName, "/");
  42.     //这里暂时不加后缀“.jpg”,防止有重复的文件,如果有,需要重命名,加了后悔不方便
  43. $newName=substr($newName,$pos_name_-strlen($newName)+1)."_";
  44.     //生成不带后缀的图片
  45. $file=$newPath.$newName;

  46. //附加asc码重命名文件
  47. for($i=0;$i<26;$i++){
  48.     //判断源文件是否存在,对于多人修改一张图片造成的不可预知的结果进行干扰
  49.     if(!is_file($src)){
  50.         break;
  51.     }
  52.     //如果目录存在
  53.     if(is_dir($newPath)){
  54.         //如果文件存在,继续循环,直到没有重名的文件
  55.         if(is_file($file.chr(97+$i).".jpg")){
  56.             continue;
  57.         }else{
  58.             //创建文件
  59.             imagejpeg($target,$file.chr(97+$i).".jpg",100);
  60.             //文件创建完成确定是否删除源文件,off为删除源文件
  61.             if($again=="off"){
  62.                 unlink($src);
  63.                 unset($_SESSION['url']);
  64.             }else{
  65.                 $_SESSION["url"]=$src;
  66.             }
  67.             
  68.             break;
  69.             
  70.         }
  71.     }else{
  72.         //创建目录
  73.         mkdir($newPath);
  74.         //创建文件
  75.         imagejpeg($target,$file.chr(97+$i).".jpg",100);
  76.         //文件创建完成确定是否删除源文件,off为删除源文件
  77.         if($again=="off"){
  78.                 unlink($src);
  79.                 unset($_SESSION['url']);
  80.         }else{
  81.                 $_SESSION["url"]=$src;
  82.         }
  83.         break;
  84.     }
  85. }
  86. Header("Location: index.php");
  87. ?>
提供下载:压缩包
 imgtool.zip  

阅读(5820) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~