Skip to Content

使用bluga.net API自动获得网站截图的PHP脚本函数

使用bluga.net提供的API,我们可以通过脚本自动获得网站截图,截图的大小为640*480,图片为JPG格式。

下面的PHP函数实现了自动获取的bluga.net网站截图的功能:

function _get_thumb_file($url_to_thumb, $bluga_api_key, $bluga_user_id) {
  $user = $bluga_user_id;
  $size = "large";
  $cache = "-1";
  $hash_str = gmstrftime("%Y%m%d") . $url_to_thumb . $bluga_api_key;
  $hash_md5 = md5($hash_str) ;
 
  $thumb_url = sprintf("http://webthumb.bluga.net/easythumb.php?user=%s&url=%s&hash=%s&size=%s&cache=%s", $user, urlencode($url_to_thumb), $hash_md5, $size, $cache);
 
  # start download the image
  $content = file_get_contents($thumb_url);
  $tmp_dir = "tmp";
  $file_name = "$tmp_dir/" . gmstrftime("%Y%m%d%H%M%S") . '.jpg';
  if(!is_dir($tmp_dir)) mkdir($tmp_dir);
  $bytes_saved = file_put_contents($file_name, $content);
  if($bytes_saved > 0) {
    echo "bytes saved by file_put_contents $bytes_saved \n\n";
    return $file_name;
  } else {
    return "";
  }
}

-- EOF-TRUEVUE --

评论

发表新评论

此内容将保密,不会被其他人看见。