PHP 百度图片搜索功能API接口开发

本文介绍了如何使用PHP开发百度图片搜索功能API接口。首先需要在百度AI平台上创建应用并获取参数,接着建立图片库并上传图片。重点讨论了`ImageIdentification.php`接口的调用方法。
摘要由CSDN通过智能技术生成

首先创建应用:
https://console.bce.baidu.com/ai/?_=&fromai=1#/ai/imagesearch/overview/index

在这里插入图片描述
会有2参数要用到:在这里插入图片描述
然后申请建库
在这里插入图片描述

随便传几张图片到里面。

接口:ImageIdentification.php

<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/4/12
 * Time: 15:07
 */

namespace app\common;

/**
 * AI图片搜索
 * Class ImageIdentification
 * @package app\common
 */
class ImageIdentification
{
   

    /**
     * @var string
     */
    protected static $client_id;

    /**
     * @var string
     */
    protected static $client_secret;

    /**
     * 构造函数
     * ImageIdentification constructor.
     */
    protected static function construct()
    {
   
        self::$client_id = 'PM4vfxjGTZt8SQBg0YhAtNDb';
        self::$client_secret = 'secret';

    }

    /**
     * @param $path
     * @param string $name
     * @param int $id
     * @return string
     * @throws \ImagickException
     */
    public static function addImageDent($path, $name = '杜小明', $id = 1)
    {
   
        $path = self::reduceSize($path);
        $token = static::getToken();
        $url = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/realtime_search/similar/add?access_token=' . $token;
        $img = file_get_contents($path);
        $img = base64_encode($img);
        $bodys = array(
            'brief' => '{"name":"' . $name . '", "id":"' . $id . '"}',
            'image' => $img,
            'tags' => "1,1"
        );
        $res = self::request_posts_http($url, $bodys
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Jason Ho

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值