private function downimg($text,$title){
$pattern="/<[img|IMG].*?src=[\‘|\"](.*?(?:[\.gif|\.jpg|\.png]))[\‘|\"].*?[\/]?>/";//匹配图片的正则式
if(preg_match_all($pattern, $text, $matches)) {
//类库
$http = new \Org\Net\Http();
$image = new \Think\Image();
foreach($matches[1] as $ak=>$av){
if(strstr($av,‘http:‘) && !strstr($av,$_SERVER[‘HTTP_HOST‘])){
$datepath=date(‘Ymd‘);
$img_name=md5($av);
$dir=‘./‘.C(‘attach_path‘).‘file/‘.$datepath.‘/‘;
if(!is_dir($dir)) mkdir($dir, 0777,1);
$save_path=$dir.$img_name.‘.jpg‘;
$htmlpath=‘/‘.C(‘attach_path‘).‘file/‘.$datepath.‘/‘.$img_name.‘.jpg‘;
//下载图片
$http->curlDownload($av,$save_path);
//图片加水印
$image->open($save_path);
$image->text(C(‘img_water‘),‘./static/2.ttf‘,18,‘#000000‘,\Think\Image::IMAGE_WATER_SOUTHEAST)->save($save_path);
$image->thumb(200, 200,\Think\Image::IMAGE_THUMB_CENTER)->save($dir.$img_name.‘_s.jpg‘);
//替换内容
//if($ak){
// $text= str_replace($matches[0][$ak],‘<img src="‘.$htmlpath.‘" >‘,$text);
//}else{
// $text= str_replace($matches[0][$ak],‘<img src="‘.$htmlpath.‘" alt="‘.$title.‘">‘,$text);
//}
$text= str_replace($matches[0][$ak],‘<img src="‘.$htmlpath.‘" >‘,$text);
}
}
}
return $text;
}