游客

本地ping网站图片版 - api接口代码

一言准备中...

介绍

PHP本地Ping网站图片版api接口
不过速度取决于服务器性能
接口需要删除php禁用函数exec 提供了9张随机背景图片 可自行修改

图片

使用

首先去删除php禁用函数
比如我是用的7.2 那么就去宝塔应用商店找到php7.2然后点击设置打开左边的禁用函数
然后看到我图片那个箭头所指的那个exec然后点删除把它删掉就好

示例

https://cdn.uuuix.com/api/v1/ping_img.php?url=www.baidu.com

代码

<?php
error_reporting(0);
header("Access-Control-Allow-Origin:*");
$host = isset($_GET['url']) ? $_GET['url'] : 'baidu.com';
$result = exec("ping -c 4 $host", $output, $returnVar);
    if ($returnVar == 0) {
        $ip_arr =  explode(' ',$output[0]);
        $ip = str_replace("(","",$ip_arr[2]);
        $ip = str_replace(")","",$ip);
        $time_arr  = explode(' ',$output[8]);
        $time_arr  = explode('/',$time_arr[3]);
        $min_time =  round($time_arr[0], 1);
        $max_time = round($time_arr[2], 1);
        $arr = array("ip"=>$ip,"min_time"=>$min_time ."ms","max_time"=>$max_time ."ms");
        $citydatas =  file_get_contents("https://api.uuuix.com/api/v1/ipc?ip=$ip");
        $citydatas = json_decode($citydatas,true);
        $citydatas = $citydatas['addr'];
        //对接获取ip地址api
        $textLines = ['域名:' .$host,'I P:'.$ip,'所属地:'.$citydatas,'延迟:最低 '.$min_time.'ms|最高 '.$max_time.'ms'];
        echo shui($textLines);
    }
    else {
        $response = array('code'=>204,'status' => 'error', 'message' => 'Ping 失败!');
        echo json_encode($response,JSON_NUMERIC_CHECK|JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
    }

function  shui($textLines){
$imagePath = './img/pingimg/shui'.rand(1,9).'.png';
// 替换为你的图片路径---随机分配图片,如果不要随机分配自行替换
//保证图片大小为800x800像素,如果要缩小或放大图片,请自行调整文字定位

$image = imagecreatefrompng($imagePath); // 如果图片是JPEG格式,其他格式请相应替换函数

// 分配颜色
$textColorList = array(
    imagecolorallocate($image, 0, 191, 255), // 域名文字颜色-森天蓝
    imagecolorallocate($image, 0, 128, 0),// ip文字颜色-绿色文字
    imagecolorallocate($image, 255, 165, 0),// 所属地文字颜色-橙色文字
    imagecolorallocate($image, 240, 129, 128) // 延迟文字颜色-橘色文字
);

// 初始化文本位置(X坐标和Y坐标)
$startX = 20; // 文本开始的X坐标
$startY = 480; // 文本开始的Y坐标
$lineHeight = 80; // 每行文字的高度
//如图片大小不等于800x800,请自行调整以上位置

// 设置字体和大小(如果需要)
$font = './font.ttf'; //字体文件路径--如有需要可自行替换
$fontSize = 40; // 字体大小

//分配内容位置坐标、颜色
$color_num = 0;
foreach($textLines as $item){
    imagettftext($image, $fontSize, 0, $startX, $startY, $textColorList[$color_num++], $font, $item);
    $startY += $lineHeight;
}

// 设置输出图片的类型
header('Content-Type: image/jpeg');
// 输出图片到浏览器
imagejpeg($image);
// 释放资源
imagedestroy($image);
}
?>
PHP

上面代码只是示例部分哈 看看就好 源码的话大家下载下面文件就好 因为上面代码的文件没有单独下载嘛

  • 本文作者:简单
  • 本文链接: https://www.uuuix.com/post-39.html
  • 版权声明:本博客所有文章除特别声明外,均默认采用 CC BY-NC-SA 4.0 许可协议。
文章很赞!支持一下吧 还没有人为TA充电
为TA充电
还没有人为TA充电
0
0
  • 支付宝打赏
    支付宝扫一扫
  • 微信打赏
    微信扫一扫
感谢支持
文章很赞!支持一下吧
关于作者
94
11
0
3
真理?

PHP获取api内容并保存

上一篇

星之阁二开API管理系统源码

下一篇
评论区
内容为空

这一切,似未曾拥有

  • 复制图片
按住ctrl可打开默认菜单