1

我想使用Azure 计算机视觉 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 提供的关于为试用版用户降级拇指质量的信息。他们声称提供高质量的缩略图,但如果这是标准,它完全没用。我想我一定忽略了什么?

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

生成的拇指源图片

4

1 回答 1

2

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

然而,第二个参数wp_remote_post()不接受URL parameters并且不会对它们做任何事情。所以在设置成wp_remote_post().

您可以先尝试使用add_query_arg()组合您的网址,

$posturl='https://api.projectoxford.ai/vision/v1.0/generateThumbnail';
$posturl=add_query_arg( array(
    'width' => 600,
    'height' => 400,
    'smartCropping' => true
), $posturl);
于 2016-06-24T06:32:22.490 回答