【问题标题】:Generate thumbnail in php, posting to Azure Computer Vision API在 php 中生成缩略图,发布到 Azure 计算机视觉 API
【发布时间】:2016-06-24 18:37:06
【问题描述】:

我想使用 Azure Computer Vision API 为我的 Wordpress 网站生成缩略图。我正在尝试使用 wp_remote_post 使其在 php 中工作,但我不知道如何解析参数?它返回一个质量非常差的缩略图,默认为 500x500px。关于如何解决这个问题的任何想法?

function get_thumbnail($URL)   //* * * * Azure Computer Vision API - v1.0 * * * *
{
$posturl='https://api.projectoxford.ai/vision/v1.0/generateThumbnail'; 

$request = wp_remote_post($posturl, array(
 'headers' => array(
    'Content-Type' => 'application/json',
    'Ocp-Apim-Subscription-Key' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'),
 'body' => array('url' => $URL)
));

if ( is_wp_error( $request ) ) 
{
    $error_message = $request->get_error_message();
    return "Something went wrong: $error_message";
    } else 
    {
      return $request['body'];
    }    
}

编辑 1

感谢@Gary 你的权利!现在裁剪是正确的,但质量有很大问题!我正在使用试用版,但我没有看到 Azure 提供有关为试用版用户降级拇指质量的信息。他们声称提供高质量的缩略图,但如果这是标准,它完全没用。 我想我一定忽略了什么?

当然,Gary,如果我的质量问题没有得到正确答案,我会以你的答案为正确关闭线程。

【问题讨论】:

  • 您是否尝试将smartCropping 设置为false。

标签: php wordpress azure computer-vision microsoft-cognitive


【解决方案1】:

根据Get Thumbnail的描述,width,heightsmartCropping应该设置为请求参数,并结合在URL中。

但是wp_remote_post() 中的第二个参数不接受URL parameters 并且不会对它们执行任何操作。所以在设置成wp_remote_post()之前需要先合并url。

你可以先尝试使用add_query_arg()来组合你的url,

$posturl='https://api.projectoxford.ai/vision/v1.0/generateThumbnail';
$posturl=add_query_arg( array(
    'width' => 600,
    'height' => 400,
    'smartCropping' => true
), $posturl);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    • 1970-01-01
    • 2019-03-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多