<?php
//独立页面-每日60秒
function luyu_sixtys(){ 
$date = file_get_contents("https://www.zhihu.com/api/v4/columns/c_1261258401923026944/items");
$date = json_decode($date);
$content = $date->data[0]->content;
$content = preg_replace('/(<a.*?>[\s\S]*?<\/a>)/','',$content);
$pattern ='<img.*?src="(.*?)">';
preg_match($pattern,$content,$matches);
$src_path = $matches[1];
$src = imagecreatefromstring(file_get_contents($src_path));
$info = getimagesize($src_path);
$x = 0;
$y = 0;
$width = 720;
$height = 350;
$final_width = 720;
$final_height = round($final_width * $height / $width);
$new_image = imagecreatetruecolor($final_width, $final_height);
imagecopyresampled($new_image, $src, 0, 0, $x, $y, $final_width, $final_height, $width, $height);
$ext = pathinfo($src_path, PATHINFO_EXTENSION);
$rand_name = date("Ymd") . "." . $ext;
$url= BLOG_URL;
if (!file_exists("content/uploadfile/60s")){
    mkdir ("content/uploadfile/60s",0777,true);
}
imagejpeg($new_image,"content/uploadfile/60s/".$rand_name);
imagedestroy($src);
imagedestroy($new_image);
$content = strip_tags($content,'<p>');
$content = '<img class="" src="'.$url.'/content/uploadfile/60s/'.$rand_name.'" />'.$content;
  return $content;
};
?>

文章目录
    收藏