sightenginehard/client-php

此包的最新版本(1.3)没有可用的许可证信息。

Sightengine PHP 客户端

1.3 2018-05-28 12:07 UTC

This package is auto-updated.

Last update: 2024-09-04 10:16:38 UTC


README

关于

使用 Sightengine 审核API来即时审核图片和视频。更多详情请访问 http://sightengine.com

开始之前,请确保您已在 https://sightengine.com 创建了账户。

安装

composer require sightengine/client-php

初始化客户端

您需要 API 用户和密钥来初始化客户端。您可以在 Sightengine 账户中找到它们。

use \Sightengine\SightengineClient;

$client = new SightengineClient('{api_user}', '{api_secret}');

审核图片

API 接受标准静态图片:JPEG、PNG、WEBP 等,以及多帧 GIF 图片。

提供多种审核引擎供您选择(如裸露检测、不适当内容检测等)。更多详情请参阅文档。

通过公共URL审核图片

# Detect nudity in an image

$output = $client->check(['nudity'])->set_url('http://img09.deviantart.net/2bd0/i/2009/276/c/9/magic_forrest_wallpaper_by_goergen.jpg')

# Detect nudity, weapons, alcohol, drugs, likely fruadulant users, celebrities and faces in an image, along with image properties and type
$output = $client->check(['nudity', 'type', 'properties', 'wad', 'face', 'scam', 'celebrity'])->set_url('http://img09.deviantart.net/2bd0/i/2009/276/c/9/magic_forrest_wallpaper_by_goergen.jpg')

审核本地图片

# Detect nudity in an image
$output = $client->check(['nudity'])->set_file('/full/path/to/image.jpg')

# Detect nudity, weapons, alcohol, drugs and faces in an image, along with image properties and type
$output = $client->check(['nudity', 'type', 'properties', 'wad', 'face'])->set_file('/full/path/to/image.jpg')

审核二进制图片

# Detect nudity in an image
$output = $client->check(['nudity'])->set_bytes($binary_image)

# Detect nudity, weapons, alcohol, drugs and faces in an image, along with image properties and type
$output = $client->check(['nudity', 'type', 'properties', 'wad', 'face'])->set_bytes($binary_image)

视频和流审核

您可以选择进行 同步异步 视频审核。

  • 同步审核简单易用:审核结果直接在 API 请求的响应中提供。同步审核仅适用于少于 1 分钟的视频。
  • 异步审核适用于任何视频或流。审核结果通过所谓的回调机制提供。您定义一个回调 URL,审核引擎会实时将审核事件发送到该 URL。

同步视频审核

注意:这仅适用于持续时间小于 1 分钟的视频。

$client->check(['nudity', 'wad'])->video_sync('https://sightengine.com/assets/stream/examples/funfair.mp4')

异步视频审核

审核视频流的第一个步骤是将视频流提交到 API,并附带一个回调 URL。

$client->check(['nudity', 'wad'])->video('https://sightengine.com/assets/stream/examples/funfair.mp4', 'https://example.com/yourcallback')

提交视频后,API 将开始向您的回调 URL 发送审核更新。

请参阅我们的 文档 获取更多详情。

反馈

为了报告错误分类,您需要报告被错误分类的图片、在此图片上运行的模型(模型为裸露、面部、类型、武器),以及图片的正确类别。

对于每个模型,都有不同的类别可以报告。以下是详细信息

裸露模型有 3 个类别

  • raw:对应原始裸露
  • partial:对应部分裸露
  • safe:对应无裸露

面部模型有 3 个类别

  • none
  • single
  • multiple

类型模型有 2 个类别

  • photo
  • illustration

武器模型有 3 个类别

  • no-weapons
  • weapons
  • no-alcohol
  • alcohol
  • no-drugs
  • drugs
$client->feedback(model, class,image)

本地图片反馈示例

$client->feedback("nudity","safe", "/full/path/to/image.jpg")
$client->feedback("type","illustration", "/full/path/to/image.jpg")
$client->feedback("nudity","raw", "/full/path/to/image.jpg")

通过公共URL的反馈示例:

$client->feedback("nudity","safe", "http://img09.deviantart.net/2bd0/i/2009/276/c/9/magic_forrest_wallpaper_by_goergen.jpg")
$client->feedback("type","illustration", "http://img09.deviantart.net/2bd0/i/2009/276/c/9/magic_forrest_wallpaper_by_goergen.jpg")
$client->feedback("nudity","raw", "http://img09.deviantart.net/2bd0/i/2009/276/c/9/magic_forrest_wallpaper_by_goergen.jpg")