cls_common_operation.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. if(!defined('IN_T'))
  3. {
  4. die('hacking attempt');
  5. }
  6. require_once __DIR__."/../../config/config.php";
  7. require_once __DIR__."/../include/cls_common.php";
  8. abstract class KrOperation{
  9. abstract protected function downloadFile($origin_url , $dest_file);
  10. abstract protected function uploadFile($local_file , $origin_file);
  11. abstract protected function video_thumb($location,$time);
  12. /*
  13. * $imgs 图片在存储服务器的路径
  14. * $temp_dir 图片下载到本地的临时路径
  15. * $kr_path KRPANO 的路径
  16. * $origin_dir 切图完成后,存储图片的目录
  17. * $cdn_host 云存储服务器域名
  18. notice : 目录必须带最后一个 /
  19. * return $imgsmain 包含场景数组
  20. */
  21. public static function slice($pk_user_main,$imgs,$origin_dir){
  22. //创建临时目录
  23. $temp_dir = KRTEMP."/".$pk_user_main."/".date('Ymd',Common::gmtime()).Common::get_rand_number()."/";
  24. Common::make_dir($temp_dir);
  25. $kr=null;
  26. $cdn_host = 'http://';
  27. switch ($GLOBALS['_lang']['global_storage']) {
  28. case 'qiniu':
  29. require_once __DIR__.'/../qiniu/cls_qiniu.php';
  30. $kr = new qiniu();
  31. $cdn_host .= $GLOBALS['_lang']['qiniu_config']['cdn_host'];
  32. break;
  33. case 'oss':
  34. require_once __DIR__.'/../oss/cls_oss.php';
  35. $kr = new Oss();
  36. $cdn_host .= $GLOBALS['_lang']['oss_config']['cdn_host'];
  37. break;
  38. }
  39. $cdn_host .='/';
  40. return $kr==null?null:$kr->slicing($imgs,$temp_dir,$cdn_host,$origin_dir);
  41. }
  42. public static function get_video_thumb($location,$time){
  43. $kr = null;
  44. switch ($GLOBALS['_lang']['global_storage']) {
  45. case 'qiniu':
  46. require_once __DIR__.'/../qiniu/cls_qiniu.php';
  47. $kr = new qiniu();
  48. break;
  49. case 'oss':
  50. require_once __DIR__.'/../oss/cls_oss.php';
  51. $kr = new Oss();
  52. break;
  53. }
  54. return $kr==null?null:$kr->video_thumb($location,$time);
  55. }
  56. private function slicing($imgs,$temp_dir,$cdn_host,$origin_dir){
  57. // $mime_type = finfo_open(FILEINFO_MIME_TYPE);
  58. $path="";
  59. $scenes = array();
  60. $imgsmain = array();
  61. foreach ($imgs as $img) {
  62. $obj = $img['imgsrc'];
  63. $view_uuid=Common::guid(16);
  64. $rpos = strrpos($obj,"/");
  65. //计算云存储上的原始文件名,为下次升级素材管理时,针对单张全景图生成预览
  66. $temp_name = substr($obj, $rpos==0?$rpos:$rpos+1);
  67. $file = $this->downloadFile($obj,$temp_dir.$temp_name);
  68. if($file!=null){
  69. $info = getimagesize($file);
  70. if(($info['0']/$info['1']==2)&&( (strpos("image/jpeg",$info['mime'])===0)||(strpos("image/tif", $info['mime'])===0))){
  71. $filename = $img['imgname'];
  72. if (strpos($filename, ".jpg")) {
  73. $filename = substr($filename , 0 , strrpos($filename , "."));
  74. }
  75. if (mb_strlen($filename)) {
  76. $filename = substr($filename, 0,100);
  77. }
  78. //生成最终文件,合并生成整个项目全景图
  79. $final_name = $temp_dir.$view_uuid.substr($obj,strrpos($obj,"."));
  80. rename($temp_dir.$temp_name, $final_name );
  81. $path=$path.$final_name." ";
  82. $source = array(
  83. 'filename' =>$filename,
  84. 'location' =>$cdn_host.$obj,
  85. 'thumb_path'=>$cdn_host.$origin_dir.$view_uuid."/thumb.jpg",
  86. 'view_uuid' =>$view_uuid
  87. );
  88. $imgsmain[] = $source;
  89. }
  90. // if(!(strpos("image/jpeg",$info['mime'])===0)&& !(strpos("image/tif", $info['mime'])===0)||($info['0']/$info['1']!=2)){
  91. // }else{
  92. // }
  93. }
  94. }
  95. if ($path!="") {
  96. //echo KRPANO." ".$path;die;
  97. //执行切图
  98. exec(KRPANO." ".$path."");
  99. //上传切好图的整个目录到服务器
  100. $dir = $temp_dir."vtour/panos/";
  101. $this ->upload($dir,$origin_dir);
  102. // $this->uploadDir($temp_dir."/vtour/panos" , $origin_dir);
  103. }
  104. return $imgsmain;
  105. }
  106. private function upload($dir,$origin_file){
  107. if(is_dir($dir))
  108. {
  109. if ($dh = opendir($dir))
  110. {
  111. while (($file = readdir($dh)) !== false)
  112. {
  113. if((is_dir($dir.$file)) && $file!="." && $file!="..")
  114. {
  115. //目录
  116. $this->upload($dir.$file."/",$origin_file.$file."/");
  117. }
  118. else
  119. {
  120. if($file!="." && $file!="..")
  121. {
  122. //上传文件
  123. $this->uploadFile($dir.$file ,$origin_file.$file);
  124. }
  125. }
  126. }
  127. closedir($dh);
  128. }
  129. }
  130. }
  131. }
  132. ?>