tinEye/tinEye-api

使用TinEye API进行反向图像搜索的库

v2.0.1 2022-07-12 13:06 UTC

This package is auto-updated.

Last update: 2024-09-12 22:19:54 UTC


README

tinEye-api是一个用于TinEye API的PHP库。TinEye API是TinEye的付费反向图像搜索解决方案,适用于专业、商业或大量使用TinEye的用户。

内容

安装

通过Composer安装。如果已安装Composer,请在您的shell中运行以下命令

$ composer require tineye/tineye-api

从旧版本迁移

如果您之前使用过任何版本的TinEye API库,那么您需要对您的代码进行一些小的修改。

现在API对象使用单个键api_key进行实例化。此键的值与您之前的private_key相同。公共密钥不再使用。

新✅

<?php
// Sandbox key
// Note that this is the same value as the old private_key
$api_key = '6mm60lsCNIB,FwOWjJqA80QZHh9BMwc-ber4u=t^';
$tineyeapi = new tineye\api\TinEyeApi($api_key);

旧❌

<?php
// Sandbox keys
$public_key = 'LCkn,2K7osVwkX95K4Oy';
$private_key = '6mm60lsCNIB,FwOWjJqA80QZHh9BMwc-ber4u=t^';
$tineyeapi = new tineye\api\TinEyeApi($private_key, $public_key);

入门

安装库后,您可以使用您的API密钥实例化一个TinEyeApi对象

<?php
$tineyeapi = new tineye\api\TinEyeApi($api_key);

如果您还没有账户,您仍然可以使用我们的API沙箱测试库,通过无参数实例化TinEyeApi对象

<?php
$tineyeapi = new tineye\api\TinEyeApi();

请注意,API沙箱不会返回真实结果;所有结果都将是一只猫的同一张图片。

创建您的TinEyeApi对象后,您就可以开始搜索了。您可以使用图像URL或通过上传图像文件提交图像数据来提交图像。您还可以检查账户中剩余搜索的数量检查TinEye索引中的图像数量

方法

常见参数

每个搜索方法(searchUrlsearchData)都接受一个可选的参数params,该参数接受一个包含以下任一选项的关联数组

<?php
$params = [
    'offset' => 0,
    'limit' => 10,
    'backlink_limit' => 100,
    'sort' => 'score',
    'order' => 'desc',
    'domain' => 'tineye.com',
];

有关可能设置的更多信息,请访问TinEye API文档

使用图像URL进行搜索

使用此方法让TinEye下载图像URL并对其与TinEye索引进行搜索。

<?php
/**
* Search for an image using an image URL
*
* @param String $url Image URL to be downloaded and searched
* @param Array $params Optional General Arguments
* @return Array Multidimensional Array of the returned JSON
*/

$tineyeapi = new tineye\api\TinEyeApi($api_key);
$search_result = $tineyeapi->searchUrl('https://tineye.com/images/meloncat.jpg');

使用图像数据搜索

使用此方法将图像上传到TinEye并对其与TinEye索引进行搜索。

<?php
/**
* Search for an image using local image data
* TinEye supports JPEG, PNG, WEBP, GIF, BMP, or TIFF image formats
*
* @param String $image_data fopen stream of an image
* @param String $file_name Name of the file to be uploaded
* @param Array $params Optional General Arguments
*
* @return Array Multidimensional Array of the returned JSON
*/
$tineyeapi = new tineye\api\TinEyeApi($api_key);
$search_result = $tineyeapi->searchData(
    fopen('./tests/meloncat.jpg', 'r'),
    'meloncat.jpg'
);

获取剩余搜索

使用此方法获取剩余搜索包的数量和状态。

<?php
/**
* Returns information on search bundles 
* @return Array Multidimensional array of the returned JSON
*/
$tineyeapi = new tineye\api\TinEyeApi($api_key);
$search_bundles = $tineyeapi->remainingSearches();

获取索引图像数量

使用此方法获取TinEye当前索引的图像数量和图像。

<?php
/**
* Returns the count of images in the TinEye index 
* @return Array Multidimensional array of the returned JSON
*/
$tineyeapi = new tineye\api\TinEyeApi($api_key);
$image_count = $tineyeapi->imageCount();

获取HTTP客户端

此方法允许访问包装的GuzzleHttp客户端。更多信息可在GuzzleHttp中找到。

<?php
/**
* Returns the wrapped Guzzle client instance
* @return GuzzleHttp\Client
*/
$tineyeapi = new tineye\api\TinEyeApi($api_key);
$guzzle_client = $tineyeapi->getClient();

支持

请将评论、建议和错误报告发送至support@tineye.com

测试

测试位于/tests文件夹中,并使用PHPunit

$ composer test

许可

本软件遵循MIT许可协议。请参阅许可文件获取更多信息。