All Products
Search
Document Center

ImageAsyncScanRequest

Last Updated: Jun 06, 2019

Interface description

SDK interfaces

  1. ImageAsyncScanRequest

Function

Asynchronous image moderation: Identifies risky scenes in images, such as adult content.It must work with ImageAsyncScanResultsRequest to query results in a polling fashion.

region

  1. ap-southeast-1

Scene

Image moderation involves a variety of scenes, and each scene corresponds to a specific label. The relationship between scenes and labels is as follows:

Scene Label Remarks
porn normal Normal image without adult content
porn sexy Sexual image
porn porn Pornographic image

For example, if you want to identify pornographic images in your business, set the “scenes” parameter in the ImageAsyncScanRequest interface to porn. Similarly, you can set “scenes” to other values to suit different identification purposes.

Image requirements

  1. The image link protocol can be either HTTP or HTTPS.
  2. The image format can be PNG, JPG, JPEG, BMP, or GIF.
  3. The maximum image size for synchronous calls is 5 MB and that for asynchronous calls is 20 MB. The download time-out period is 3 seconds.
  4. The recommended image pixel is not smaller than 256 x 256. If the pixel is excessively small, the identification performance may be adversely affected.
  5. The response period of the Image Moderation API is determined by the image download period. Make sure that the storage service of the images is stable. It is recommended to store the images in OSS or cache them in CDN.

Call methods

Asynchronous image moderation – interface call example

  1. <?php
  2. include_once 'aliyuncs/aliyun-php-sdk-core/Config.php';
  3. use Green\Request\V20170112 as Green;
  4. date_default_timezone_set("PRC");
  5. //Replace with your accessKeyId and accessKeySecret
  6. $iClientProfile = DefaultProfile::getProfile("ap-southeast-1", "Your accessKeyId", "your accessKeySecret");
  7. DefaultProfile::addEndpoint("ap-southeast-1", "ap-southeast-1", "Green", "green.ap-southeast-1.aliyuncs.com");
  8. $client = new DefaultAcsClient($iClientProfile);
  9. $request = new Green\ImageAsyncScanRequest();
  10. $request->setMethod("POST");
  11. $request->setAcceptFormat("JSON");
  12. $task1 = array('dataId' => uniqid(),
  13. 'url' => 'http://xxx.jpg',
  14. 'time' => round(microtime(true)*1000)
  15. );
  16. /**
  17. * porn
  18. */
  19. $request->setContent(json_encode(array("tasks" => array($task1),
  20. "scenes" => array("porn"))));
  21. try {
  22. $response = $client->getAcsResponse($request);
  23. print_r($response);
  24. if(200 == $response->code){
  25. $taskResults = $response->data;
  26. foreach ($taskResults as $taskResult) {
  27. if(200 == $taskResult->code){
  28. $taskId = $taskResult->taskId;
  29. print_r($taskId);
  30. // Save taskId for querying results later, refer to ImageAsyncScanResultsRequest
  31. }else{
  32. print_r("task process fail:" + $response->code);
  33. }
  34. }
  35. }else{
  36. print_r("detect not success. code:" + $response->code);
  37. }
  38. } catch (Exception $e) {
  39. print_r($e);
  40. }