Private Function Downimg ($text, $title) {
$pattern = "/<[img| Img].*?src=[\ ' |\ "] (. *? (?: [\.gif|\.jpg|\.png])) [\ ' |\ '].*? [\/]?>/];//match the regular style of the picture
if (Preg_match_all ($pattern, $text, $matches)) {
Class Library
$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 ';
Download image
$http->curldownload ($av, $save _path);
Picture plus watermark
$image->open ($save _path);
$image->text (C (' Img_water '), './static/2.ttf ',, ' #000000 ', \think\image::image_water_southeast)->save ($ Save_path);
$image->thumb (200,\think\image::image_thumb_center)->save ($dir. $img _name. ' _s.jpg ');
Replace content
if ($ak) {
$text = Str_replace ($matches [0][$ak], ' ', $text);
}else{
$text = Str_replace ($matches [0][$ak], ' ', $text);
//}
$text = Str_replace ($matches [0][$ak], ' ', $text);
}
}
}
return $text;
}
Download remote pictures to local implementation code using Thinkphp's own HTTP class