2016-07-03 7 views
0

Я использую cloudinary API обнаружения лица таким образом:PHP обнаружения лица: cloudinary Количество API лицо

require 'cloudinary/Cloudinary.php'; 
require 'cloudinary/Uploader.php'; 
require 'cloudinary/Api.php'; 

\Cloudinary::config(array(
    "cloud_name" => "xxxxxxxxxxxx", 
    "api_key" => "9999999999999", 
    "api_secret" => "xxxxxxxxxxxxx" 
)); 

$img = 'guy.jpg'; 
$imgid = time() . 'guy'; 

\Cloudinary\Uploader::upload($img, array("public_id" => $imgid)); 

$url = 'http://res.cloudinary.com/xxxxxx/image/upload/c_fill,g_face,h_500,w_375/' . $imgid . '.jpg'; 
file_put_contents('cropped' . $img, file_get_contents($url)); 

Но что мне нужно, это:

\Cloudinary\Uploader::upload($img, array("public_id" => $imgid)); 

// what I need >>> 
if('face_count != 1') 
{ 
    exit; 
} 
// <<< what I need 

$url = 'http://res.cloudinary.com/xxxxxx/image/upload/c_fill,g_face,h_500,w_375/' . $imgid . '.jpg'; 
file_put_contents('cropped' . $img, file_get_contents($url)); 

Я не понимаю, как используйте face_count из дока здесь: http://cloudinary.com/documentation/image_transformations#specifying_conditions

+0

Это зависит от того, чего вы хотели бы достичь в случае (face-count! = 1). Обычно такой URL-адрес будет выглядеть так: https: // res.cloudinary.com/xxxxxx/image/upload/if_fc_eq_1/c_fill,g_face,h_500,w_375/if_else/some-fallback-transformation/if_end/sample.jpg Во всяком случае, изображение должно быть доставлено, в противном случае это приведет к ошибке (сломанное изображение). –

ответ

0

Спасибо за ответ Надав, я решил это так:

$url = 'http://res.cloudinary.com/xxxxxxx/image/upload/if_fc_eq_1,c_fill,g_face,h_500,w_375/' . $bildnamecloud . '.jpg'; 
file_put_contents('cropped' . $bildname, file_get_contents($url)); 

\Cloudinary\Uploader::destroy($bildnamecloud); 


list($width, $height) = getimagesize('cropped' . $bildname); 

if($width == 375 AND $height == 500) 
{ 

} 
else 
{ 

} 
Смежные вопросы