在php中生成缩略图,发布到Azure Computer Vision API [英] Generate thumbnail in php, posting to Azure Computer Vision API

查看:81
本文介绍了在php中生成缩略图,发布到Azure Computer Vision API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to use Azure Computer Vision API to generate thumbnails for my Wordpress site. I'm trying to make it work in php with wp_remote_post, but i don't know how to parse the parameters ? It returns a thumbnail in really bad quality and default 500x500px. Any ideas on how to resolve this issue ?

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提供的有关降低试用版用户拇指质量的信息.他们声称提供高质量的缩略图,但是如果那是标准的,那就完全没用了. 我一定忽略了我猜的东西?

Thanks @Gary your right! Now the cropping is correct, but i got a huge problem with the quality! I'm using a trial but i see no info from Azure on downgrading the thumb quality for trial users. They are claiming to deliver high quality thumbnails, but if thats the standard it's totaly useless. I must have overlooked something i guess?

当然,加里,如果我对我的质量问题没有正确的答案,我会以你的答案正确为准关闭话题.

Of course Gary, if i get no correct answer on my quality question i will close the thread with your answer as correct.

推荐答案

根据获取缩略图,应将widthheightsmartCropping设置为请求参数,并应在URL中进行组合.

According the description of Get Thumbnail, the width,height and smartCropping should be set as request parameters which should combined in URL.

但是 wp_remote_post() 中的第二个参数不接受URL parameters并且会他们什么都没有.因此,在设置为wp_remote_post()之前,您需要先组合url.

However the second args in wp_remote_post() do not accept the URL parameters and will do nothing on them. So you need to combine the url first before set into wp_remote_post().

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

You can try to use add_query_arg() to combine your url first,

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

这篇关于在php中生成缩略图,发布到Azure Computer Vision API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆