图片抓取函数 与 图片上传函数

图片抓取函数
function manage_img_data($imgUrl){
 global $resrootpath;
 $size = getimagesize($imgUrl);
 preg_match('/width="(\\d+)" height="(\\d+)"/',$size[3],$wh);
 $width = $wh[1];
 $height = $wh[2];
 $imgExt = strrchr($imgUrl,".");//获得后缀
 if($imgExt == ".jpg" && $width < 201 && $height < 201){  

  $sec = explode(" ", microtime());  
  $micro = explode(".", $sec[0]);
  $fileName = $sec[1].substr($micro[1], 0, 3);
  //$fileName = time();//命名
  $filePath = substr($fileName,-4,2).'/'.substr($fileName,-2,2).'/';
  $imgNames = $fileName.$imgExt;
  ob_start();
  readfile($imgUrl);//读入缓存
  $ob_img = ob_get_contents();//取出缓存
  ob_end_clean(); //清空 
  

  $abspath = $resrootpath."images/wiki/";
  $picpath = $abspath.$filePath.$imgNames;   

  //$thp = "/www/webroot/wappp/3g/plugins/movie/images/".$filePath.$imgNames;//$filePath
  $createFile=@fopen($picpath, "a");
  if($createFile != false){
   fwrite($createFile,$ob_img);
   fclose($createFile);
    $rsyncpath = "images/wiki/".$filePath;
    $cmd = "/www/log/bin/rsync.4.3gpp.res.img.sh ".$_COOKIE["_uname"]." ".$rsyncpath.$filename;
    exec($cmd);
   return $imgNames;
  }else{
   return null;
  } 
 }else{
  return null;
 } 
}

图片上传程序


function zd_word_uploadImage($FILES,$type){
 global $resrootpath; 
 
 $img_name = $FILES['name'];
 $tmp_name = $FILES['tmp_name'];
    $imgExtArr = array('.gif','.jpg','.JPEG');//图片格式
 $imgExt = strrchr($img_name,".");//获得后缀
 
 if (in_array($imgExt,$imgExtArr)){
  //取时间
  $sec = explode(" ", microtime());  
  $micro = explode(".", $sec[0]);
  $times = $sec[1].substr($micro[1], 0, 3);
  
  $subTime = substr($times,-4,2)."/".substr($times,-2)."/"; //截取时间路径
  
  $imgNames = $times.$imgExt;//图片名字
  
  $picpath = "images/wiki/".$subTime.$imgNames;//资源路径

  $muf = move_uploaded_file($tmp_name,$resrootpath.$picpath);
  
  if($muf){//上传源图片
   //同步原图
   $cmd01 = "/www/log/bin/rsync.4.3gpp.res.img.sh ".$_COOKIE["_uname"]." ".$picpath;
         exec($cmd01);
        
   //=======缩图
   if($type == 1){//长
    $width = 80; $height = 60;
   }elseif($type == 2){//竖
    $width = 60; $height = 80;
   }else{//方版
    $width = 80; $height = 80;
   }
   
   
   $newImgName = $times."_".$width."_".$height.$imgExt;; //缩图图片名称
   
   $smallpicpath = "images/wiki/".$subTime.$newImgName; //缩图的路径
   
   $cmd02 = "convert ".$resrootpath.$picpath." -coalesce ".$resrootpath.$smallpicpath;//开始缩图
   exec($cmd02); 
     
   $cmd03 = "convert -resize ".$width."x".$height."! ".$resrootpath.$smallpicpath." ".$resrootpath.$smallpicpath;
   exec($cmd03);
   
   //同步缩图图片
   $cmd04 = "/www/log/bin/rsync.4.3gpp.res.img.sh ".$_COOKIE["_uname"]." ".$smallpicpath;
         exec($cmd04);
   
         return $newImgName;
  }else{
   return null;
  }  
  
    }else{
     return null;
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值