mirror of https://github.com/helloxz/imgurl.git
xiaoz
7 years ago
32 changed files with 6308 additions and 41 deletions
@ -0,0 +1,95 @@
@@ -0,0 +1,95 @@
|
||||
<?php |
||||
/* |
||||
@name:万象优图API处理接口 |
||||
@author:xiaoz.me |
||||
*/ |
||||
error_reporting(E_ALL^E_NOTICE^E_WARNING^E_DEPRECATED); |
||||
//载入配置 |
||||
include_once('../config.php'); |
||||
|
||||
//载入万象优图SDK |
||||
require_once '../sdk/wxyt/index.php'; |
||||
use QcloudImage\CIClient; |
||||
$client = new CIClient($identify['APP_ID'], $identify['SECRET_ID'], $identify['SECRET_KEY'], $identify['BUCKET']); |
||||
$client->setTimeout(60); |
||||
|
||||
//获取图片地址 |
||||
$url = $_GET['url']; |
||||
//获取上级目录地址 |
||||
|
||||
//对URL进行替换 |
||||
$url = str_replace($config['domain'],'',$url); |
||||
$imgdir = explode('/',$url);//对目录进行分割 |
||||
|
||||
//如果链接是管理员目录则不鉴黄 |
||||
if($imgdir[0] == $config['admindir']) { |
||||
$re_data = array( |
||||
"code" => 0, |
||||
"result" => 0, |
||||
"confidence"=> 0 |
||||
); |
||||
|
||||
echo $re_data = json_encode($re_data); |
||||
exit; |
||||
} |
||||
//如果不是游客目录 |
||||
if($config['userdir'] != $imgdir[0]) { |
||||
//echo $imgdir[0]; |
||||
echo '非法请求'; |
||||
exit; |
||||
} |
||||
//重组完整图片 |
||||
$imgurl = $config['domain'].$url; |
||||
$imginfo = ($client->pornDetect(array('urls'=>array($imgurl)))); |
||||
|
||||
$imginfo = json_decode($imginfo); |
||||
|
||||
//获取状态码,0为成功 |
||||
//$code = $imginfo->http_code; |
||||
//转换为数组 |
||||
$imginfo = object2array($imginfo); |
||||
//状态码,0为成功 |
||||
$code = $imginfo['result_list']['0']->code; |
||||
$imginfo = object2array($imginfo['result_list']['0']->data); |
||||
//识别结果,0 正常,1 黄图,2 疑似图片 |
||||
$result = $imginfo['result']; |
||||
//识别评分,分数越高,越可能是黄图 |
||||
$confidence = $imginfo['confidence']; |
||||
|
||||
//重新返回json数据 |
||||
$re_data = array( |
||||
"code" => $code, |
||||
"result" => $result, |
||||
"confidence"=> $confidence |
||||
); |
||||
|
||||
//严格模式,如果是色情图片或疑似色情图片均放到回收站 |
||||
if(($re_data['result'] == 1) || ($re_data['result'] == 2)) { |
||||
//获取图片地址 |
||||
$url = dirname(dirname(__FILE__)).'/'.$url; |
||||
//回收站地址 |
||||
$recycle = dirname(dirname(__FILE__))."/recycle/".end($imgdir); |
||||
//移动到回收站 |
||||
if(copy($url,$recycle)){ |
||||
unlink($url); //删除图片 |
||||
} |
||||
} |
||||
|
||||
echo $re_data = json_encode($re_data); |
||||
exit; |
||||
?> |
||||
|
||||
<?php |
||||
//对象转数组 |
||||
function object2array($object) { |
||||
if (is_object($object)) { |
||||
foreach ($object as $key => $value) { |
||||
$array[$key] = $value; |
||||
} |
||||
} |
||||
else { |
||||
$array = $object; |
||||
} |
||||
return $array; |
||||
} |
||||
?> |
@ -0,0 +1,90 @@
@@ -0,0 +1,90 @@
|
||||
<?php |
||||
/* |
||||
@name:TinyPNG图片压缩接口 |
||||
@author:xiaoz.me |
||||
*/ |
||||
|
||||
//载入SDK |
||||
require_once("../sdk/tinypng/Tinify/Exception.php"); |
||||
require_once("../sdk/tinypng/Tinify/ResultMeta.php"); |
||||
require_once("../sdk/tinypng/Tinify/Result.php"); |
||||
require_once("../sdk/tinypng/Tinify/Source.php"); |
||||
require_once("../sdk/tinypng/Tinify/Client.php"); |
||||
require_once("../sdk/tinypng/Tinify.php"); |
||||
//载入配置文件 |
||||
require_once("../config.php"); |
||||
|
||||
//获取图片URL地址 |
||||
$imgurl = $_GET['url']; |
||||
//获取URI |
||||
$imguri = str_replace($config['domain'],"",$imgurl); |
||||
//echo $imguri; |
||||
//仅获取域名 |
||||
$domain = str_replace("http://","",$config['domain']); |
||||
$domain = str_replace("https://","",$domain); |
||||
$domain = explode("/",$domain); //最终的目的是取出域名 |
||||
|
||||
|
||||
//搜索域名是否匹配 |
||||
$sdomain = strpos($imgurl,$domain[0]); |
||||
|
||||
if($sdomain == false) { |
||||
echo '地址不合法'; |
||||
exit; |
||||
} |
||||
//合法的域名,那我们继续咯 |
||||
//在判断下目录是否合法 |
||||
$imgdir = explode("/",$imguri); |
||||
//如果目录不是访客目录也不是管理员目录,那就不处理咯 |
||||
if(($imgdir[0] != $config['userdir']) && ($imgdir[0] != $config['admindir'])) { |
||||
echo '地址不合法'; |
||||
exit; |
||||
} |
||||
//ok,上面都过了,判断下图片类型 |
||||
//使用exif_imagetype函数来判断文件类型 |
||||
$imguri = '../'.$imguri; |
||||
$file_type = exif_imagetype($imguri); |
||||
switch ( $file_type ) |
||||
{ |
||||
case IMAGETYPE_JPEG: |
||||
tinypng($config['tinypng'],$config['domain'],$imguri,$imgurl); |
||||
$redata = array("code" => 1,"type" => $file_type); |
||||
echo json_encode($redata); |
||||
break; |
||||
case IMAGETYPE_PNG: |
||||
tinypng($config['tinypng'],$config['domain'],$imguri,$imgurl); |
||||
$redata = array("code" => 1,"type" => $file_type); |
||||
echo json_encode($redata); |
||||
break; |
||||
default: |
||||
$redata = array("code" => 0,"type" => $file_type); |
||||
echo json_encode($redata); |
||||
break; |
||||
} |
||||
?> |
||||
|
||||
<?php |
||||
//压缩图片 |
||||
function tinypng($api,$host,$imgfile,$imgurl){ |
||||
if($api == '') { |
||||
echo '未开启TinyPNG'; |
||||
exit; |
||||
} |
||||
else{ |
||||
Tinify\setKey($api); |
||||
Tinify\fromFile($imgfile)->toFile($imgfile); |
||||
//获取主机名 |
||||
$host = $host."/api/"; |
||||
//对压缩后的图片鉴黄 |
||||
$ch = curl_init($host."identify.php?url=".$imgurl) ; |
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求 不验证>证书和hosts |
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); |
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true) ; // 获取数据返回 |
||||
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true) ; // 在启用 CURLOPT_RETURNTRANSFER 时候将获取数据返回 |
||||
$output = curl_exec($ch) ; |
||||
curl_close($ch); |
||||
|
||||
return $imgfile; |
||||
} |
||||
} |
||||
?> |
After Width: | Height: | Size: 4.2 KiB |
@ -0,0 +1,102 @@
@@ -0,0 +1,102 @@
|
||||
<?php |
||||
error_reporting(E_ALL^E_NOTICE^E_WARNING^E_DEPRECATED); |
||||
//载入配置 |
||||
include_once('./config.php'); |
||||
//载入header |
||||
include_once('./header.php'); |
||||
//权限判断 |
||||
$id = md5($config['username'].$config['password']); |
||||
$uid = $_COOKIE['uid']; |
||||
if($id != $uid) { |
||||
echo "<h3 class = 'text-center'>权限不足</h3>"; |
||||
exit; |
||||
} |
||||
?> |
||||
<div class="container" style = "margin-top:40px;"> |
||||
<div class="row"> |
||||
<div class="col-lg-10 col-md-offset-1"> |
||||
<!--图片预览--> |
||||
<div class="col-lg-6"> |
||||
<img id = "viewid" src="./static/view.jpg" class="img-thumbnail img-responsive"> |
||||
</div> |
||||
<!--图片预览END--> |
||||
<div class="col-lg-6"> |
||||
<table class="table table-striped"> |
||||
<tbody> |
||||
<?php |
||||
function get_files($dir) { |
||||
$files = array(); |
||||
|
||||
for (; $dir->valid(); $dir->next()) { |
||||
if ($dir->isDir() && !$dir->isDot()) { |
||||
if ($dir->haschildren()) { |
||||
$files = array_merge($files, get_files($dir->getChildren())); |
||||
}; |
||||
}else if($dir->isFile()){ |
||||
$files[] = $dir->getPathName(); |
||||
} |
||||
} |
||||
return $files; |
||||
} |
||||
|
||||
$path = 'recycle'; |
||||
$dir = new RecursiveDirectoryIterator($path); |
||||
$fname = get_files($dir); |
||||
$num = count($fname) - 1; |
||||
|
||||
for($i = 0;$i <= $num;$i++) { |
||||
$fname[$i] = str_replace("\\","/",$fname[$i]); |
||||
//如果文件是空的,则终止循环 |
||||
?> |
||||
<tr id = "row<?php echo $i; ?>"> |
||||
<td onmouseover = "return view('<?php echo $config['domain'].$fname[$i] ?>');"> |
||||
<?php |
||||
echo "<a href = "."'".$config['domain'].$fname[$i]."' target = '_blank'>"."$fname[$i]</a>"; |
||||
?> |
||||
</td> |
||||
<td> |
||||
<?php |
||||
if(isset($_COOKIE['uid'])) { |
||||
echo "<a href = \"javascript:;\" onclick = \"del('$fname[$i]',$i);\">删除</a>"; |
||||
} |
||||
?> |
||||
</td> |
||||
</tr> |
||||
<?php } ?> |
||||
</tbody> |
||||
</table> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
<script> |
||||
function view(imgurl) { |
||||
$("#viewid").src; |
||||
$("#viewid").attr('src',imgurl); |
||||
} |
||||
//删除图片 |
||||
function del(filedir,rowid) { |
||||
//行id |
||||
var rowid = 'row' + rowid; |
||||
//确认删除? |
||||
var msg = "确认删除?"; |
||||
if (confirm(msg)==true){ |
||||
$.get("./functions.php?type=delete&dir="+filedir,function(data,status){ |
||||
//删除成功 |
||||
if(data == 'ok') { |
||||
$("#"+rowid).remove(); |
||||
} |
||||
else{ |
||||
alert(data); //删除失败,弹出报错 |
||||
} |
||||
}); |
||||
}else{ |
||||
return false; |
||||
} |
||||
} |
||||
</script> |
||||
|
||||
<?php |
||||
//载入页脚 |
||||
include_once('./footer.php'); |
||||
?> |
@ -0,0 +1,5 @@
@@ -0,0 +1,5 @@
|
||||
<IfModule mod_rewrite.c> |
||||
RewriteEngine On |
||||
order allow,deny |
||||
deny from all |
||||
</IfModule> |
@ -0,0 +1,7 @@
@@ -0,0 +1,7 @@
|
||||
User-Agent: * |
||||
Disallow: /recycle/ |
||||
Disallow: /sdk/ |
||||
Disallow: /api/ |
||||
Disallow: /temp/ |
||||
Disallow: /upload/ |
||||
Disallow: /static/ |
@ -0,0 +1,96 @@
@@ -0,0 +1,96 @@
|
||||
<?php |
||||
|
||||
namespace Tinify; |
||||
|
||||
const VERSION = "1.5.2"; |
||||
|
||||
class Tinify { |
||||
private static $key = NULL; |
||||
private static $appIdentifier = NULL; |
||||
private static $proxy = NULL; |
||||
|
||||
private static $compressionCount = NULL; |
||||
private static $client = NULL; |
||||
|
||||
public static function setKey($key) { |
||||
self::$key = $key; |
||||
self::$client = NULL; |
||||
} |
||||
|
||||
public static function setAppIdentifier($appIdentifier) { |
||||
self::$appIdentifier = $appIdentifier; |
||||
self::$client = NULL; |
||||
} |
||||
|
||||
public static function setProxy($proxy) { |
||||
self::$proxy = $proxy; |
||||
self::$client = NULL; |
||||
} |
||||
|
||||
public static function getCompressionCount() { |
||||
return self::$compressionCount; |
||||
} |
||||
|
||||
public static function setCompressionCount($compressionCount) { |
||||
self::$compressionCount = $compressionCount; |
||||
} |
||||
|
||||
public static function getClient() { |
||||
if (!self::$key) { |
||||
throw new AccountException("Provide an API key with Tinify\setKey(...)"); |
||||
} |
||||
|
||||
if (!self::$client) { |
||||
self::$client = new Client(self::$key, self::$appIdentifier, self::$proxy); |
||||
} |
||||
|
||||
return self::$client; |
||||
} |
||||
|
||||
public static function setClient($client) { |
||||
self::$client = $client; |
||||
} |
||||
} |
||||
|
||||
function setKey($key) { |
||||
return Tinify::setKey($key); |
||||
} |
||||
|
||||
function setAppIdentifier($appIdentifier) { |
||||
return Tinify::setAppIdentifier($appIdentifier); |
||||
} |
||||
|
||||
function setProxy($proxy) { |
||||
return Tinify::setProxy($proxy); |
||||
} |
||||
|
||||
function getCompressionCount() { |
||||
return Tinify::getCompressionCount(); |
||||
} |
||||
|
||||
function compressionCount() { |
||||
return Tinify::getCompressionCount(); |
||||
} |
||||
|
||||
function fromFile($path) { |
||||
return Source::fromFile($path); |
||||
} |
||||
|
||||
function fromBuffer($string) { |
||||
return Source::fromBuffer($string); |
||||
} |
||||
|
||||
function fromUrl($string) { |
||||
return Source::fromUrl($string); |
||||
} |
||||
|
||||
function validate() { |
||||
try { |
||||
Tinify::getClient()->request("post", "/shrink"); |
||||
} catch (AccountException $err) { |
||||
if ($err->status == 429) return true; |
||||
throw $err; |
||||
} catch (ClientException $err) { |
||||
return true; |
||||
} |
||||
} |
@ -0,0 +1,160 @@
@@ -0,0 +1,160 @@
|
||||
<?php |
||||
|
||||
namespace Tinify; |
||||
|
||||
class Client { |
||||
const API_ENDPOINT = "https://api.tinify.com"; |
||||
|
||||
const RETRY_COUNT = 1; |
||||
const RETRY_DELAY = 500; |
||||
|
||||
private $options; |
||||
|
||||
public static function userAgent() { |
||||
$curl = curl_version(); |
||||
return "Tinify/" . VERSION . " PHP/" . PHP_VERSION . " curl/" . $curl["version"]; |
||||
} |
||||
|
||||
private static function caBundle() { |
||||
return __DIR__ . "/../data/cacert.pem"; |
||||
} |
||||
|
||||
function __construct($key, $app_identifier = NULL, $proxy = NULL) { |
||||
$curl = curl_version(); |
||||
|
||||
if (!($curl["features"] & CURL_VERSION_SSL)) { |
||||
throw new ClientException("Your curl version does not support secure connections"); |
||||
} |
||||
|
||||
if ($curl["version_number"] < 0x071201) { |
||||
$version = $curl["version"]; |
||||
throw new ClientException("Your curl version ${version} is outdated; please upgrade to 7.18.1 or higher"); |
||||
} |
||||
|
||||
$this->options = array( |
||||
CURLOPT_BINARYTRANSFER => true, |
||||
CURLOPT_RETURNTRANSFER => true, |
||||
CURLOPT_HEADER => true, |
||||
CURLOPT_USERPWD => "api:" . $key, |
||||
CURLOPT_CAINFO => self::caBundle(), |
||||
CURLOPT_SSL_VERIFYPEER => true, |
||||
CURLOPT_USERAGENT => join(" ", array_filter(array(self::userAgent(), $app_identifier))), |
||||
); |
||||
|
||||
if ($proxy) { |
||||
$parts = parse_url($proxy); |
||||
if (isset($parts["host"])) { |
||||
$this->options[CURLOPT_PROXYTYPE] = CURLPROXY_HTTP; |
||||
$this->options[CURLOPT_PROXY] = $parts["host"]; |
||||
} else { |
||||
throw new ConnectionException("Invalid proxy"); |
||||
} |
||||
|
||||
if (isset($parts["port"])) { |
||||
$this->options[CURLOPT_PROXYPORT] = $parts["port"]; |
||||
} |
||||
|
||||
$creds = ""; |
||||
if (isset($parts["user"])) $creds .= $parts["user"]; |
||||
if (isset($parts["pass"])) $creds .= ":" . $parts["pass"]; |
||||
|
||||
if ($creds) { |
||||
$this->options[CURLOPT_PROXYAUTH] = CURLAUTH_ANY; |
||||
$this->options[CURLOPT_PROXYUSERPWD] = $creds; |
||||
} |
||||
} |
||||
} |
||||
|
||||
function request($method, $url, $body = NULL) { |
||||
$header = array(); |
||||
if (is_array($body)) { |
||||
if (!empty($body)) { |
||||
$body = json_encode($body); |
||||
array_push($header, "Content-Type: application/json"); |
||||
} else { |
||||
$body = NULL; |
||||
} |
||||
} |
||||
|
||||
for ($retries = self::RETRY_COUNT; $retries >= 0; $retries--) { |
||||
if ($retries < self::RETRY_COUNT) { |
||||
usleep(self::RETRY_DELAY * 1000); |
||||
} |
||||
|
||||
$request = curl_init(); |
||||
if ($request === false || $request === null) { |
||||
throw new ConnectionException( |
||||
"Error while connecting: curl extension is not functional or disabled." |
||||
); |
||||
} |
||||
|
||||
curl_setopt_array($request, $this->options); |
||||
|
||||
$url = strtolower(substr($url, 0, 6)) == "https:" ? $url : self::API_ENDPOINT . $url; |
||||
curl_setopt($request, CURLOPT_URL, $url); |
||||
curl_setopt($request, CURLOPT_CUSTOMREQUEST, strtoupper($method)); |
||||
|
||||
if (count($header) > 0) { |
||||
curl_setopt($request, CURLOPT_HTTPHEADER, $header); |
||||
} |
||||
|
||||
if ($body) { |
||||
curl_setopt($request, CURLOPT_POSTFIELDS, $body); |
||||
} |
||||
|
||||
$response = curl_exec($request); |
||||
|
||||
if (is_string($response)) { |
||||
$status = curl_getinfo($request, CURLINFO_HTTP_CODE); |
||||
$headerSize = curl_getinfo($request, CURLINFO_HEADER_SIZE); |
||||
curl_close($request); |
||||
|
||||
$headers = self::parseHeaders(substr($response, 0, $headerSize)); |
||||
$body = substr($response, $headerSize); |
||||
|
||||
if (isset($headers["compression-count"])) { |
||||
Tinify::setCompressionCount(intval($headers["compression-count"])); |
||||
} |
||||
|
||||
if ($status >= 200 && $status <= 299) { |
||||
return (object) array("body" => $body, "headers" => $headers); |
||||
} |
||||
|
||||
$details = json_decode($body); |
||||
if (!$details) { |
||||
$message = sprintf("Error while parsing response: %s (#%d)", |
||||
PHP_VERSION_ID >= 50500 ? json_last_error_msg() : "Error", |
||||
json_last_error()); |
||||
$details = (object) array( |
||||
"message" => $message, |
||||
"error" => "ParseError" |
||||
); |
||||
} |
||||
|
||||
if ($retries > 0 && $status >= 500) continue; |
||||
throw Exception::create($details->message, $details->error, $status); |
||||
} else { |
||||
$message = sprintf("%s (#%d)", curl_error($request), curl_errno($request)); |
||||
curl_close($request); |
||||
if ($retries > 0) continue; |
||||
throw new ConnectionException("Error while connecting: " . $message); |
||||
} |
||||
} |
||||
} |
||||
|
||||
protected static function parseHeaders($headers) { |
||||
if (!is_array($headers)) { |
||||
$headers = explode("\r\n", $headers); |
||||
} |
||||
|
||||
$res = array(); |
||||
foreach ($headers as $header) { |
||||
if (empty($header)) continue; |
||||
$split = explode(":", $header, 2); |
||||
if (count($split) === 2) { |
||||
$res[strtolower($split[0])] = trim($split[1]); |
||||
} |
||||
} |
||||
return $res; |
||||
} |
||||
} |
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
<?php |
||||
|
||||
namespace Tinify; |
||||
|
||||
class Exception extends \Exception { |
||||
public $status; |
||||
|
||||
public static function create($message, $type, $status) { |
||||
if ($status == 401 || $status == 429) { |
||||
$klass = "Tinify\AccountException"; |
||||
} else if($status >= 400 && $status <= 499) { |
||||
$klass = "Tinify\ClientException"; |
||||
} else if($status >= 500 && $status <= 599) { |
||||
$klass = "Tinify\ServerException"; |
||||
} else { |
||||
$klass = "Tinify\Exception"; |
||||
} |
||||
|
||||
if (empty($message)) $message = "No message was provided"; |
||||
return new $klass($message, $type, $status); |
||||
} |
||||
|
||||
function __construct($message, $type = NULL, $status = NULL) { |
||||
$this->status = $status; |
||||
if ($status) { |
||||
parent::__construct($message . " (HTTP " . $status . "/" . $type . ")"); |
||||
} else { |
||||
parent::__construct($message); |
||||
} |
||||
} |
||||
} |
||||
|
||||
class AccountException extends Exception {} |
||||
class ClientException extends Exception {} |
||||
class ServerException extends Exception {} |
||||
class ConnectionException extends Exception {} |
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
<?php |
||||
|
||||
namespace Tinify; |
||||
|
||||
class Result extends ResultMeta { |
||||
protected $data; |
||||
|
||||
public function __construct($meta, $data) { |
||||
$this->meta = $meta; |
||||
$this->data = $data; |
||||
} |
||||
|
||||
public function data() { |
||||
return $this->data; |
||||
} |
||||
|
||||
public function toBuffer() { |
||||
return $this->data; |
||||
} |
||||
|
||||
public function toFile($path) { |
||||
return file_put_contents($path, $this->toBuffer()); |
||||
} |
||||
|
||||
public function size() { |
||||
return intval($this->meta["content-length"]); |
||||
} |
||||
|
||||
public function mediaType() { |
||||
return $this->meta["content-type"]; |
||||
} |
||||
|
||||
public function contentType() { |
||||
return $this->mediaType(); |
||||
} |
||||
} |
@ -0,0 +1,23 @@
@@ -0,0 +1,23 @@
|
||||
<?php |
||||
|
||||
namespace Tinify; |
||||
|
||||
class ResultMeta { |
||||
protected $meta; |
||||
|
||||
public function __construct($meta) { |
||||
$this->meta = $meta; |
||||
} |
||||
|
||||
public function width() { |
||||
return intval($this->meta["image-width"]); |
||||
} |
||||
|
||||
public function height() { |
||||
return intval($this->meta["image-height"]); |
||||
} |
||||
|
||||
public function location() { |
||||
return isset($this->meta["location"]) ? $this->meta["location"] : null; |
||||
} |
||||
} |
@ -0,0 +1,69 @@
@@ -0,0 +1,69 @@
|
||||
<?php |
||||
|
||||
namespace Tinify; |
||||
|
||||
class Source { |
||||
private $url, $commands; |
||||
|
||||
public static function fromFile($path) { |
||||
return self::fromBuffer(file_get_contents($path)); |
||||
} |
||||
|
||||
public static function fromBuffer($string) { |
||||
$response = Tinify::getClient()->request("post", "/shrink", $string); |
||||
return new self($response->headers["location"]); |
||||
} |
||||
|
||||
public static function fromUrl($url) { |
||||
$body = array("source" => array("url" => $url)); |
||||
$response = Tinify::getClient()->request("post", "/shrink", $body); |
||||
return new self($response->headers["location"]); |
||||
} |
||||
|
||||
public function __construct($url, $commands = array()) { |
||||
$this->url = $url; |
||||
$this->commands = $commands; |
||||
} |
||||
|
||||
public function preserve() { |
||||
$options = $this->flatten(func_get_args()); |
||||
$commands = array_merge($this->commands, array("preserve" => $options)); |
||||
return new self($this->url, $commands); |
||||
} |
||||
|
||||
public function resize($options) { |
||||
$commands = array_merge($this->commands, array("resize" => $options)); |
||||
return new self($this->url, $commands); |
||||
} |
||||
|
||||
public function store($options) { |
||||
$response = Tinify::getClient()->request("post", $this->url, |
||||
array_merge($this->commands, array("store" => $options))); |
||||
return new Result($response->headers, $response->body); |
||||
} |
||||
|
||||
public function result() { |
||||
$response = Tinify::getClient()->request("get", $this->url, $this->commands); |
||||
return new Result($response->headers, $response->body); |
||||
} |
||||
|
||||
public function toFile($path) { |
||||
return $this->result()->toFile($path); |
||||
} |
||||
|
||||
public function toBuffer() { |
||||
return $this->result()->toBuffer(); |
||||
} |
||||
|
||||
private static function flatten($options) { |
||||
$flattened = array(); |
||||
foreach ($options as $option) { |
||||
if (is_array($option)) { |
||||
$flattened = array_merge($flattened, $option); |
||||
} else { |
||||
array_push($flattened, $option); |
||||
} |
||||
} |
||||
return $flattened; |
||||
} |
||||
} |
@ -0,0 +1,48 @@
@@ -0,0 +1,48 @@
|
||||
<?php |
||||
/** |
||||
* Signature create related functions. |
||||
*/ |
||||
namespace QcloudImage; |
||||
|
||||
/** |
||||
* Auth class for creating reusable signature. |
||||
*/ |
||||
class Auth { |
||||
|
||||
public function __construct($appId, $secretId, $secretKey) { |
||||
$this->appId = $appId; |
||||
$this->secretId = $secretId; |
||||
$this->secretKey = $secretKey; |
||||
} |
||||
/** |
||||
* Return the appId |
||||
*/ |
||||
public function getAppId() { |
||||
return $this->appId; |
||||
} |
||||
|
||||
/** |
||||
* Create reusable signature. |
||||
* This signature will expire at time()+$howlong timestamp. |
||||
* Return the signature on success. |
||||
* Return false on fail. |
||||
*/ |
||||
public function getSign($bucket, $howlong = 30) { |
||||
if ($howlong <= 0) { |
||||
return false; |
||||
} |
||||
|
||||
$now = time(); |
||||
$expiration = $now + $howlong; |
||||
$random = rand(); |
||||
|
||||
$plainText = "a=".$this->appId."&b=$bucket&k=".$this->secretId."&e=$expiration&t=$now&r=$random&f="; |
||||
$bin = hash_hmac('SHA1', $plainText, $this->secretKey, true); |
||||
|
||||
return base64_encode($bin.$plainText); |
||||
} |
||||
|
||||
private $appId = ""; |
||||
private $secretId = ""; |
||||
private $secretKey = ""; |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,46 @@
@@ -0,0 +1,46 @@
|
||||
<?php |
||||
/** |
||||
* Some settings for SDK. |
||||
*/ |
||||
namespace QcloudImage; |
||||
|
||||
/** |
||||
* Conf class. |
||||
*/ |
||||
class Conf { |
||||
private static $VERSION = '1.0.0'; |
||||
private static $SERVER_ADDR = 'service.image.myqcloud.com'; |
||||
private static $HEADER_HOST = 'service.image.myqcloud.com'; |
||||
private $REQ_TIMEOUT = 60; |
||||
private $SCHEME = 'http'; |
||||
|
||||
public function useHttp() { |
||||
$this->SCHEME = 'http'; |
||||
} |
||||
public function useHttps() { |
||||
$this->SCHEME = 'https'; |
||||
} |
||||
public function setTimeout($timeout) { |
||||
if ($timeout > 0) { |
||||
$this->REQ_TIMEOUT = $timeout; |
||||
} |
||||
} |
||||
public function timeout() { |
||||
return $this->REQ_TIMEOUT; |
||||
} |
||||
public function host() { |
||||
return self::$HEADER_HOST; |
||||
} |
||||
|
||||
public function buildUrl($uri) { |
||||
return $this->SCHEME.'://'.self::$SERVER_ADDR.'/'.ltrim($uri, "/"); |
||||
} |
||||
|
||||
public static function getUa($appid = null) { |
||||
$ua = 'CIPhpSDK/'.self::$VERSION.' ('.php_uname().')'; |
||||
if ($appid) { |
||||
$ua .= " User($appid)"; |
||||
} |
||||
return $ua; |
||||
} |
||||
} |
@ -0,0 +1,28 @@
@@ -0,0 +1,28 @@
|
||||
<?php |
||||
/** |
||||
* Error defination. |
||||
*/ |
||||
namespace QcloudImage; |
||||
|
||||
class Error { |
||||
|
||||
/** |
||||
* Create reusable signature. |
||||
* This signature will expire at time()+$howlong timestamp. |
||||
* Return the signature on success. |
||||
* Return false on fail. |
||||
*/ |
||||
public static function json($code, $message, $httpcode = 0) { |
||||
return json_encode(array( |
||||
'code' => $code, |
||||
'message' => $message, |
||||
'httpcode' => $httpcode, |
||||
'data' => json_decode('{}',true) |
||||
)); |
||||
} |
||||
|
||||
public static $Param = -1; |
||||
public static $Network = -2; |
||||
public static $FilePath = -3; |
||||
public static $Unknown = -4; |
||||
} |
@ -0,0 +1,108 @@
@@ -0,0 +1,108 @@
|
||||
<?php |
||||
/** |
||||
* Http Client use curl. |
||||
*/ |
||||
namespace QcloudImage; |
||||
|
||||
function my_curl_reset($handler) { |
||||
curl_setopt($handler, CURLOPT_URL, ''); |
||||
curl_setopt($handler, CURLOPT_HTTPHEADER, array()); |
||||
curl_setopt($handler, CURLOPT_POSTFIELDS, array()); |
||||
curl_setopt($handler, CURLOPT_TIMEOUT, 0); |
||||
curl_setopt($handler, CURLOPT_SSL_VERIFYPEER, false); |
||||
curl_setopt($handler, CURLOPT_SSL_VERIFYHOST, 0); |
||||
} |
||||
|
||||
class HttpClient { |
||||
|
||||
public function __destory() { |
||||
if ($this->curlHandler) { |
||||
curl_close($this->curlHandler); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* send http request |
||||
* @param array $request http请求信息 |
||||
* url : 请求的url地址 |
||||
* method : 请求方法,'get', 'post', 'put', 'delete', 'head' |
||||
* data : 请求数据,如有设置,则method为post |
||||
* header : 需要设置的http头部 |
||||
* host : 请求头部host |
||||
* timeout : 请求超时时间 |
||||
* cert : ca文件路径 |
||||
* ssl_version: SSL版本号 |
||||
* @return string http请求响应 |
||||
*/ |
||||
public function sendRequest($request) { |
||||
if (!is_array($request) || !isset($request["url"])) { |
||||
return false; |
||||
} |
||||
if ($this->curlHandler) { |
||||
if (function_exists('curl_reset')) { |
||||
curl_reset($this->curlHandler); |
||||
} else { |
||||
my_curl_reset($this->curlHandler); |
||||
} |
||||
} else { |
||||
$this->curlHandler = curl_init(); |
||||
} |
||||
|
||||
curl_setopt($this->curlHandler, CURLOPT_URL, $request['url']); |
||||
|
||||
$method = 'GET'; |
||||
if (isset($request['method']) && |
||||
in_array(strtolower($request['method']), array('get', 'post', 'put', 'delete', 'head'))) { |
||||
$method = strtoupper($request['method']); |
||||
} else if (isset($request['data'])) { |
||||
$method = 'POST'; |
||||
} |
||||
|
||||
$header = isset($request['header']) ? $request['header'] : array(); |
||||
$header[] = 'Method:'.$method; |
||||
$header[] = 'Connection: keep-alive'; |
||||
if ('POST' == $method) { |
||||
$header[] = 'Expect: '; |
||||
} |
||||
|
||||
isset($request['host']) && $header[] = 'Host:' . $request['host']; |
||||
curl_setopt($this->curlHandler, CURLOPT_HTTPHEADER, $header); |
||||
curl_setopt($this->curlHandler, CURLOPT_RETURNTRANSFER, 1); |
||||
curl_setopt($this->curlHandler, CURLOPT_CUSTOMREQUEST, $method); |
||||
isset($request['timeout']) && curl_setopt($this->curlHandler, CURLOPT_TIMEOUT, $request['timeout']); |
||||
isset($request['data']) && in_array($method, array('POST', 'PUT')) && |
||||
curl_setopt($this->curlHandler, CURLOPT_POSTFIELDS, $request['data']); |
||||
$ssl = substr($request['url'], 0, 8) == "https://" ? true : false; |
||||
if (isset($request['cert'])) { |
||||
curl_setopt($this->curlHandler, CURLOPT_SSL_VERIFYPEER,true); |
||||
curl_setopt($this->curlHandler, CURLOPT_CAINFO, $request['cert']); |
||||
curl_setopt($this->curlHandler, CURLOPT_SSL_VERIFYHOST,2); |
||||
if (isset($request['ssl_version'])) { |
||||
curl_setopt($this->curlHandler, CURLOPT_SSLVERSION, $request['ssl_version']); |
||||
} else { |
||||
curl_setopt($this->curlHandler, CURLOPT_SSLVERSION, 4); |
||||
} |
||||
} else if ($ssl) { |
||||
curl_setopt($this->curlHandler, CURLOPT_SSL_VERIFYPEER,false); //true any ca |
||||
curl_setopt($this->curlHandler, CURLOPT_SSL_VERIFYHOST,1); //check only host |
||||
if (isset($request['ssl_version'])) { |
||||
curl_setopt($this->curlHandler, CURLOPT_SSLVERSION, $request['ssl_version']); |
||||
} else { |
||||
curl_setopt($this->curlHandler, CURLOPT_SSLVERSION, 4); |
||||
} |
||||
} |
||||
$ret = curl_exec($this->curlHandler); |
||||
$this->httpInfo = curl_getinfo($this->curlHandler); |
||||
return $ret; |
||||
} |
||||
|
||||
public function statusCode() { |
||||
if ($this->httpInfo) { |
||||
return $this->httpInfo['http_code']; |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
private $httpInfo; |
||||
private $curlHandler; |
||||
} |
@ -0,0 +1,224 @@
@@ -0,0 +1,224 @@
|
||||
# tencentyun/image-php-sdk-v2.0 |
||||
腾讯云 [万象优图(Cloud Image)](https://www.qcloud.com/product/ci) SDK for PHP |
||||
|
||||
## 安装(直接下载源码集成) |
||||
### 直接下载源码集成 |
||||
从github下载源码,并加载image-php-sdk-v2.0/index.php就可以了。 |
||||
调用请参考sample.php |
||||
|
||||
### 1. 在腾讯云申请业务的授权 |
||||
授权包括: |
||||
|
||||
APP_ID |
||||
SECRET_ID |
||||
SECRET_KEY |
||||
BUCKET |
||||
|
||||
### 2. 创建对应操作类的对象 |
||||
如果要使用图片,需要创建图片操作类对象 |
||||
|
||||
require_once __DIR__ . '/index.php'; |
||||
use QcloudImage\CIClient; |
||||
|
||||
$client = new CIClient('APP_ID', 'SECRET_ID', 'SECRET_KEY', 'BUCKET'); |
||||
$client->setTimeout(30); |
||||
|
||||
### 3. 调用对应的方法 |
||||
在创建完对象后,根据实际需求,调用对应的操作方法就可以了。sdk提供的方法包括:图片识别、人脸识别及人脸核身等。 |
||||
|
||||
#### 3.1 图片识别 |
||||
图片识别包括:图片鉴黄、图片标签、OCR-身份证识别及OCR-名片识别。 |
||||
|
||||
##### 图片鉴黄 |
||||
|
||||
```php |
||||
//单个或多个图片Url |
||||
var_dump ($client->pornDetect(array('urls'=>array('YOUR URL A', |
||||
'YOUR URL B')))); |
||||
//单个或多个图片File |
||||
var_dump ($client->pornDetect(array('files'=>array('F:\pic\你好.jpg','G:\pic\test2.jpg')))); |
||||
``` |
||||
|
||||
##### 图片标签 |
||||
|
||||
```php |
||||
//单个图片url |
||||
var_dump ($client->tagDetect(array('url'=>'YOUR URL'))); |
||||
//单个图片file |
||||
var_dump ($client->tagDetect(array('file'=>'G:\pic\hot1.jpg'))); |
||||
//单个图片内容 |
||||
var_dump ($client->tagDetect(array('buffer'=>file_get_contents('G:\pic\hot1.jpg')))); |
||||
``` |
||||
|
||||
##### OCR-身份证识别 |
||||
|
||||
```php |
||||
//单个或多个图片Url,识别身份证正面 |
||||
var_dump ($client->idcardDetect(array('urls'=>array('YOUR URL A', |
||||
'YOUR URL B')), 0)); |
||||
//单个或多个图片file,识别身份证正面 |
||||
var_dump ($client->idcardDetect(array('files'=>array('F:\pic\id6_zheng.jpg', 'F:\pic\id2_zheng.jpg')), 0)); |
||||
//单个或多个图片内容,识别身份证正面 |
||||
var_dump ($client->idcardDetect(array('buffers'=>array(file_get_contents('F:\pic\id6_zheng.jpg'), |
||||
file_get_contents('F:\pic\id2_zheng.jpg'))), 0)); |
||||
|
||||
//单个或多个图片Url,识别身份证反面 |
||||
var_dump ($client->idcardDetect(array('urls'=>array('YOUR URL C', |
||||
'YOUR URL D')), 1)); |
||||
//单个或多个图片file,识别身份证反面 |
||||
var_dump ($client->idcardDetect(array('files'=>array('F:\pic\id5_fan.jpg', 'F:\pic\id7_fan.png')), 1)); |
||||
//单个或多个图片内容,识别身份证反面 |
||||
var_dump ($client->idcardDetect(array('buffers'=>array(file_get_contents('F:\pic\id5_fan.jpg'), |
||||
file_get_contents('F:\pic\id7_fan.jpg'))), 1)); |
||||
``` |
||||
|
||||
##### OCR-名片识别 |
||||
```php |
||||
//单个或多个图片Url |
||||
var_dump ($client->namecardDetect(array('urls'=>array('YOUR URL A', |
||||
'YOUR URL B')), 0)); |
||||
//单个或多个图片file, |
||||
var_dump ($client->namecardDetect(array('files'=>array('F:\pic\r.jpg', 'F:\pic\name2.jpg')), 1)); |
||||
//单个或多个图片内容 |
||||
var_dump ($client->namecardDetect(array('buffers'=>array(file_get_contents('F:\pic\name1.jpg'), |
||||
file_get_contents('F:\pic\name2.jpg'))), 0)); |
||||
``` |
||||
|
||||
#### 3.2 人脸识别 |
||||
人脸识别包括:人脸检测、五官定位、个体信息管理、人脸验证、人脸对比及人脸检索。 |
||||
|
||||
#### 人脸检测 |
||||
|
||||
```php |
||||
//单个图片Url, mode:1为检测最大的人脸 , 0为检测所有人脸 |
||||
var_dump ($client->faceDetect(array('url'=>'YOUR URL'), 1)); |
||||
//单个图片file,mode:1为检测最大的人脸 , 0为检测所有人脸 |
||||
var_dump ($client->faceDetect(array('file'=>'F:\pic\face1.jpg'),0)); |
||||
//单个图片内容,mode:1为检测最大的人脸 , 0为检测所有人脸 |
||||
var_dump ($client->faceDetect(array('buffer'=>file_get_contents('F:\pic\face1.jpg')), 1)); |
||||
``` |
||||
|
||||
##### 五官定位 |
||||
|
||||
```php |
||||
//单个图片Url,mode:1为检测最大的人脸 , 0为检测所有人脸 |
||||
var_dump ($client->faceShape(array('url'=>'YOUR URL'),1)); |
||||
//单个图片file,mode:1为检测最大的人脸 , 0为检测所有人脸 |
||||
var_dump ($client->faceShape(array('file'=>'F:\pic\face1.jpg'),0)); |
||||
//单个图片内容,mode:1为检测最大的人脸 , 0为检测所有人脸 |
||||
var_dump ($client->faceShape(array('buffer'=>file_get_contents('F:\pic\face1.jpg')), 1)); |
||||
``` |
||||
|
||||
##### 个体信息管理 |
||||
```php |
||||
//个体创建,创建一个Person,并将Person放置到group_ids指定的组当中,不存在的group_id会自动创建。 |
||||
//创建一个Person, 使用图片url |
||||
var_dump ($client->faceNewPerson('person1111', array('group11',), array('url'=>'YOUR URL'), 'xiaoxin')); |
||||
//创建一个Person, 使用图片file |
||||
var_dump ($client->faceNewPerson('person2111', array('group11',), array('file'=>'F:\pic\hot1.jpg'))); |
||||
//创建一个Person, 使用图片内容 |
||||
var_dump ($client->faceNewPerson('person3111', array('group11',), array('buffer'=>file_get_contents('F:\pic\zhao1.jpg')))); |
||||
|
||||
//增加人脸,将一组Face加入到一个Person中。 |
||||
//将单个或者多个Face的url加入到一个Person中 |
||||
var_dump ($client->faceAddFace('person1111', array('urls'=>array('YOUR URL A', |
||||
'YOUR URL B')))); |
||||
//将单个或者多个Face的file加入到一个Person中 |
||||
var_dump ($client->faceAddFace('person2111', array('files'=>array('F:\pic\yang.jpg','F:\pic\yang2.jpg')))); |
||||
//将单个或者多个Face的文件内容加入到一个Person中 |
||||
var_dump ($client->faceAddFace('person3111', array('buffers'=>array(file_get_contents('F:\pic\yang.jpg'),file_get_contents('F:\pic\yang2.jpg'))))); |
||||
|
||||
// 删除人脸,删除一个person下的face |
||||
var_dump ($client->faceDelFace('person1', array('12346',))); |
||||
|
||||
//设置信息 |
||||
var_dump ($client->faceSetInfo('person1', 'fanbing')); |
||||
|
||||
//获取信息 |
||||
var_dump ($client->faceGetInfo('person1')); |
||||
|
||||
//获取组列表 |
||||
var_dump ($client->faceGetGroupIds()); |
||||
|
||||
//获取人列表 |
||||
var_dump ($client->faceGetPersonIds('group1')); |
||||
|
||||
//获取人脸列表 |
||||
var_dump ($client->faceGetFaceIds('person1')); |
||||
|
||||
//获取人脸信息 |
||||
var_dump ($client->faceGetFaceInfo('1704147773393235686')); |
||||
|
||||
//删除个人 |
||||
var_dump ($client->faceDelPerson('person11')); |
||||
``` |
||||
|
||||
##### 人脸验证 |
||||
给定一个Face和一个Person,返回是否是同一个人的判断以及置信度 |
||||
|
||||
```php |
||||
//单个图片Url |
||||
var_dump ($client->faceVerify('person1', array('url'=>'YOUR URL'))); |
||||
//单个图片file |
||||
var_dump ($client->faceVerify('person3111', array('file'=>'F:\pic\yang3.jpg'))); |
||||
//单个图片内容 |
||||
var_dump ($client->faceVerify('person3111', array('buffer'=>file_get_contents('F:\pic\yang3.jpg')))); |
||||
``` |
||||
|
||||
##### 人脸检索 |
||||
对于一个待识别的人脸图片,在一个Group中识别出最相似的Top5 Person作为其身份返回,返回的Top5中按照相似度从大到小排列。 |
||||
|
||||
```php |
||||
//单个文件url |
||||
var_dump ($client->faceIdentify('group1', array('url'=>'YOUR URL'))); |
||||
//单个文件file |
||||
var_dump ($client->faceIdentify('group11', array('file'=>'F:\pic\yang3.jpg'))); |
||||
//单个文件内容 |
||||
var_dump ($client->faceIdentify('group11', array('buffer'=>file_get_contents('F:\pic\yang3.jpg')))); |
||||
``` |
||||
|
||||
##### 人脸对比 |
||||
|
||||
```php |
||||
//两个对比图片的文件url |
||||
var_dump ($client->faceCompare(array('url'=>"YOUR URL A"), |
||||
array('url'=>'YOUR URL B'))); |
||||
//两个对比图片的文件file |
||||
var_dump ($client->faceCompare(array('file'=>'F:\pic\yang.jpg'), array('file'=>'F:\pic\yang2.jpg'))); |
||||
//两个对比图片的文件内容 |
||||
var_dump ($client->faceCompare(array('file'=>'F:\pic\yang.jpg'), array('file'=>'F:\pic\yang2.jpg'))); |
||||
``` |
||||
|
||||
|
||||
#### 3.3 人脸核身 |
||||
|
||||
##### 身份证识别对比 |
||||
|
||||
```php |
||||
//身份证url |
||||
var_dump ($client->faceIdCardCompare('xxxxxxxxxxx', 'xxxxxxxxxxx', array('url'=>'YOUR URL'))); |
||||
//身份证文件file |
||||
var_dump ($client->faceIdCardCompare('xxxxxxxxxxx', 'xxxxxxxxxxx', array('file'=>'F:\pic\idcard.jpg'))); |
||||
//身份证文件内容 |
||||
var_dump ($client->faceIdCardCompare('xxxxxxxxxxx', 'xxxxxxxxxxx', array('buffer'=>file_get_contents('F:\pic\idcard.jpg')))); |
||||
``` |
||||
|
||||
##### 活体检测—获取唇语验证码 |
||||
|
||||
```php |
||||
$obj = $client->faceLiveGetFour(); |
||||
var_dump ($obj); |
||||
$validate_data = $obj['data']['validate_data']; |
||||
``` |
||||
|
||||
##### 活体检测-视频与用户照片的比对 |
||||
|
||||
```php |
||||
var_dump ($client->faceLiveDetectFour($validate_data, array('file'=>'F:\pic\ZOE_0171.mp4'), False, array('F:\pic\idcard.jpg'))); |
||||
``` |
||||
|
||||
##### 活体检测-视频与身份证高清照片的比对 |
||||
|
||||
```php |
||||
var_dump ($client->faceIdCardLiveDetectFour($validate_data, array('file'=>'F:\pic\ZOE_0171.mp4'), 'xxxxxxxxxxx', 'xxxxxxxxxxx')); |
||||
``` |
@ -0,0 +1,11 @@
@@ -0,0 +1,11 @@
|
||||
<?php |
||||
|
||||
function classLoader($class) |
||||
{ |
||||
$path = str_replace('\\', DIRECTORY_SEPARATOR, $class); |
||||
$file = __DIR__ . DIRECTORY_SEPARATOR . $path . '.php'; |
||||
if (file_exists($file)) { |
||||
require_once $file; |
||||
} |
||||
} |
||||
spl_autoload_register('classLoader'); |
@ -0,0 +1,3 @@
@@ -0,0 +1,3 @@
|
||||
<?php |
||||
|
||||
require_once __DIR__ . '/autoload.php'; |
@ -0,0 +1,150 @@
@@ -0,0 +1,150 @@
|
||||
<?php |
||||
|
||||
require_once __DIR__ . '/index.php'; |
||||
use QcloudImage\CIClient; |
||||
|
||||
$appid = 'YOUR_APPID'; |
||||
$secretId = 'YOUR_SECRETID'; |
||||
$secretKey = 'YOUR_SECRETKEY'; |
||||
$bucket = 'YOUR_BUCKET'; |
||||
|
||||
$client = new CIClient($appid, $secretId, $secretKey, $bucket); |
||||
$client->setTimeout(30); |
||||
|
||||
//图片鉴黄 |
||||
//单个或多个图片Url |
||||
var_dump ($client->pornDetect(array('urls'=>array('YOUR URL A','YOUR URL B')))); |
||||
//单个或多个图片File |
||||
var_dump ($client->pornDetect(array('files'=>array('F:\pic\你好.jpg','G:\pic\test2.jpg')))); |
||||
|
||||
//图片标签 |
||||
//单个图片url |
||||
var_dump ($client->tagDetect(array('url'=>'YOUR URL'))); |
||||
//单个图片file |
||||
var_dump ($client->tagDetect(array('file'=>'G:\pic\hot1.jpg'))); |
||||
//单个图片内容 |
||||
var_dump ($client->tagDetect(array('buffer'=>file_get_contents('G:\pic\hot1.jpg')))); |
||||
|
||||
//身份证识别 |
||||
//单个或多个图片Url,识别身份证正面 |
||||
var_dump ($client->idcardDetect(array('urls'=>array('YOUR URL A', 'YOUR URL B')), 0)); |
||||
//单个或多个图片file,识别身份证正面 |
||||
var_dump ($client->idcardDetect(array('files'=>array('F:\pic\id6_zheng.jpg', 'F:\pic\id2_zheng.jpg')), 0)); |
||||
//单个或多个图片内容,识别身份证正面 |
||||
var_dump ($client->idcardDetect(array('buffers'=>array(file_get_contents('F:\pic\id6_zheng.jpg'), file_get_contents('F:\pic\id2_zheng.jpg'))), 0)); |
||||
|
||||
//单个或多个图片Url,识别身份证反面 |
||||
var_dump ($client->idcardDetect(array('urls'=>array('YOUR URL A', 'YOUR URL B')), 1)); |
||||
//单个或多个图片file,识别身份证反面 |
||||
var_dump ($client->idcardDetect(array('files'=>array('F:\pic\id5_fan.jpg', 'F:\pic\id7_fan.png')), 1)); |
||||
//单个或多个图片内容,识别身份证反面 |
||||
var_dump ($client->idcardDetect(array('buffers'=>array(file_get_contents('F:\pic\id5_fan.jpg'), file_get_contents('F:\pic\id7_fan.png'))), 1)); |
||||
|
||||
//名片识别 |
||||
//单个或多个图片Url |
||||
var_dump ($client->namecardDetect(array('urls'=>array('YOUR URL A', 'YOUR URL B')), 0)); |
||||
//单个或多个图片file, |
||||
var_dump ($client->namecardDetect(array('files'=>array('F:\pic\r.jpg', 'F:\pic\name2.jpg')), 1)); |
||||
//单个或多个图片内容 |
||||
var_dump ($client->namecardDetect(array('buffers'=>array(file_get_contents('F:\pic\name1.jpg'), file_get_contents('F:\pic\name2.jpg'))), 0)); |
||||
|
||||
//人脸检测 |
||||
//单个图片Url, mode:1为检测最大的人脸 , 0为检测所有人脸 |
||||
var_dump ($client->faceDetect(array('url'=>'YOUR URL'), 1)); |
||||
//单个图片file,mode:1为检测最大的人脸 , 0为检测所有人脸 |
||||
var_dump ($client->faceDetect(array('file'=>'F:\pic\face1.jpg'),0)); |
||||
//单个图片内容,mode:1为检测最大的人脸 , 0为检测所有人脸 |
||||
var_dump ($client->faceDetect(array('buffer'=>file_get_contents('F:\pic\face1.jpg')), 1)); |
||||
|
||||
//五官定位 |
||||
//单个图片Url,检测最大的人脸 |
||||
var_dump ($client->faceShape(array('url'=>'YOUR URL'),1)); |
||||
//单个图片Url,检测所有人脸 |
||||
var_dump ($client->faceShape(array('file'=>'F:\pic\face1.jpg'),0)); |
||||
//单个图片Url,检测所有人脸 |
||||
var_dump ($client->faceShape(array('buffer'=>file_get_contents('F:\pic\face1.jpg')), 1)); |
||||
|
||||
|
||||
//创建一个Person,并将Person放置到group_ids指定的组当中, 使用图片url |
||||
var_dump ($client->faceNewPerson('person1111', array('group11',), array('url'=>'YOUR URL'), 'xiaoxin')); |
||||
//创建一个Person,并将Person放置到group_ids指定的组当中, 使用图片file |
||||
var_dump ($client->faceNewPerson('person2111', array('group11',), array('file'=>'F:\pic\hot1.jpg'))); |
||||
//创建一个Person,并将Person放置到group_ids指定的组当中, 使用图片内容 |
||||
var_dump ($client->faceNewPerson('person3111', array('group11',), array('buffer'=>file_get_contents('F:\pic\zhao1.jpg')))); |
||||
|
||||
|
||||
//增加人脸,将单个或者多个Face的url加入到一个Person中.注意,一个Face只能被加入到一个Person中。 一个Person最多允许包含20个Face |
||||
var_dump ($client->faceAddFace('person_one', array('urls'=>array('YOUR URL A','YOUR URL B')))); |
||||
//增加人脸,将单个或者多个Face的file加入到一个Person中.注意,一个Face只能被加入到一个Person中。 一个Person最多允许包含20个Face |
||||
var_dump ($client->faceAddFace('person_two', array('files'=>array('F:\pic\yang.jpg','F:\pic\yang2.jpg')))); |
||||
//增加人脸,将单个或者多个Face的文件内容加入到一个Person中.注意,一个Face只能被加入到一个Person中。 一个Person最多允许包含20个Face |
||||
var_dump ($client->faceAddFace('person_three', array('buffers'=>array(file_get_contents('F:\pic\yang.jpg'),file_get_contents('F:\pic\yang2.jpg'))))); |
||||
|
||||
//删除人脸 |
||||
var_dump ($client->faceDelFace('person_one', array('one',))); |
||||
//设置信息 |
||||
var_dump ($client->faceSetInfo('person_one', 'fanbing')); |
||||
//获取信息 |
||||
var_dump ($client->faceGetInfo('person_one')); |
||||
//获取组列表 |
||||
var_dump ($client->faceGetGroupIds()); |
||||
//获取人列表 |
||||
var_dump ($client->faceGetPersonIds('group1')); |
||||
//获取人脸列表 |
||||
var_dump ($client->faceGetFaceIds('person_one')); |
||||
//获取人脸信息 |
||||
var_dump ($client->faceGetFaceInfo('1704147773393235686')); |
||||
//删除个人 |
||||
var_dump ($client->faceDelPerson('person_one')); |
||||
|
||||
//人脸验证 |
||||
//单个图片Url |
||||
var_dump ($client->faceVerify('person1', array('url'=>'YOUR URL'))); |
||||
//单个图片file |
||||
var_dump ($client->faceVerify('person3111', array('file'=>'F:\pic\yang3.jpg'))); |
||||
//单个图片内容 |
||||
var_dump ($client->faceVerify('person3111', array('buffer'=>file_get_contents('F:\pic\yang3.jpg')))); |
||||
|
||||
//人脸检索 |
||||
//单个文件url |
||||
var_dump ($client->faceIdentify('group1', array('url'=>'YOUR URL'))); |
||||
//单个文件file |
||||
var_dump ($client->faceIdentify('group11', array('file'=>'F:\pic\yang3.jpg'))); |
||||
//单个文件内容 |
||||
var_dump ($client->faceIdentify('group11', array('buffer'=>file_get_contents('F:\pic\yang3.jpg')))); |
||||
|
||||
//人脸对比 |
||||
//两个对比图片的文件url |
||||
var_dump ($client->faceCompare(array('url'=>"YOUR URL A"), array('url'=>'YOUR URL B'))); |
||||
//两个对比图片的文件file |
||||
var_dump ($client->faceCompare(array('file'=>'F:\pic\yang.jpg'), array('file'=>'F:\pic\yang2.jpg'))); |
||||
//两个对比图片的文件内容 |
||||
var_dump ($client->faceCompare( array('buffer'=>file_get_contents('F:\pic\yang.jpg')), array('buffer'=>file_get_contents('F:\pic\yang3.jpg')))); |
||||
|
||||
|
||||
//身份证识别对比 |
||||
//身份证url |
||||
var_dump ($client->faceIdCardCompare('ID CARD NUM', 'NAME', array('url'=>'YOUR URL'))); |
||||
//身份证文件file |
||||
var_dump ($client->faceIdCardCompare('ID CARD NUM', 'NAME', array('file'=>'F:\pic\idcard.jpg'))); |
||||
//身份证文件内容 |
||||
var_dump ($client->faceIdCardCompare('ID CARD NUM', 'NAME', array('buffer'=>file_get_contents('F:\pic\idcard.jpg')))); |
||||
|
||||
|
||||
//人脸核身 |
||||
//活体检测第一步:获取唇语(验证码) |
||||
$obj = $client->faceLiveGetFour(); |
||||
var_dump ($obj); |
||||
$faceObj = json_decode($obj, true); |
||||
var_dump ($faceObj); |
||||
$validate_data = ''; |
||||
if ($faceObj && isset($faceObj['data']['validate_data'])) { |
||||
$validate_data = $faceObj['data']['validate_data']; |
||||
} |
||||
var_dump ($validate_data); |
||||
|
||||
//活体检测第二步:检测 |
||||
var_dump ($client->faceLiveDetectFour($validate_data, array('file'=>'F:\pic\ZOE_0171.mp4'), False, array('F:\pic\idcard.jpg'))); |
||||
//活体检测第二步:检测--对比指定身份信息 |
||||
var_dump ($client->faceIdCardLiveDetectFour($validate_data, array('file'=>'F:\pic\ZOE_0171.mp4'), '330782198802084329', '季锦锦')); |
||||
|
@ -0,0 +1,44 @@
@@ -0,0 +1,44 @@
|
||||
<?php |
||||
require_once 'wxyt/index.php'; |
||||
use QcloudImage\CIClient; |
||||
$client = new CIClient('', '', '', ''); |
||||
$client->setTimeout(30); |
||||
$imginfo = ($client->pornDetect(array('urls'=>array('https://imgurl.org/upload/1712/caace16a4a5b0646.png')))); |
||||
|
||||
$imginfo = json_decode($imginfo); |
||||
|
||||
//获取状态码,0为成功 |
||||
//$code = $imginfo->http_code; |
||||
//转换为数组 |
||||
$imginfo = object2array($imginfo); |
||||
//状态码,0为成功 |
||||
$code = $imginfo['result_list']['0']->code; |
||||
$imginfo = object2array($imginfo['result_list']['0']->data); |
||||
//识别结果,0 正常,1 黄图,2 疑似图片 |
||||
$result = $imginfo['result']; |
||||
//识别评分,分数越高,越可能是黄图 |
||||
$confidence = $imginfo['confidence']; |
||||
|
||||
//重新返回json数据 |
||||
$re_data = array( |
||||
"code" => $code, |
||||
"result" => $result, |
||||
"confidence"=> $confidence |
||||
); |
||||
echo $re_data = json_encode($re_data); |
||||
?> |
||||
|
||||
<?php |
||||
//对象转数组 |
||||
function object2array($object) { |
||||
if (is_object($object)) { |
||||
foreach ($object as $key => $value) { |
||||
$array[$key] = $value; |
||||
} |
||||
} |
||||
else { |
||||
$array = $object; |
||||
} |
||||
return $array; |
||||
} |
||||
?> |
Loading…
Reference in new issue