Skip to main content

Image Moderation

Image Moderation provides sensitive content moderation services such as pornography detection, political content detection, and violent and terrorist content detection, effectively identifying prohibited images and mitigating compliance risks.

Features

Moderation TypeDescription
Pornography DetectionDetects pornographic and suggestive content, effectively reducing manual review costs, suitable for various social platforms and instant messaging applications, and helps platforms avoid pornography-related risks
Violence and Terrorism DetectionIdentifies terrorists, cult organizations, firearms and ammunition, bloody violence, and other terrorist content in images, helping platforms avoid legal risks
Political Content DetectionDetects politically sensitive content in images through technologies like facial recognition and image generalization, helping platforms promptly comply with legal requirements and mitigate public opinion risks
Ad DetectionIdentifies ad-guiding images to help platforms block advertising information

!You can use this extension capability not only in Cloud Functions but also on the client side. The file read-write permission policies are consistent with Cloud Storage, reducing your additional permission management efforts.

Prerequisites

CloudBase has been provisioned.

Extension Configuration Information

You can configure the following parameters:

  • Environment ID: Select the environment to deploy to, specifying where it will be used.

Billing

This extension uses CloudBase or other Tencent Cloud services, which may incur relevant fees:

When using CloudBase extensions, you only pay for the cloud resources you consume; CloudBase is billed separately from other cloud resources. You can view detailed information in the Billing Center.

Enabled APIs and Created Resources

  • Type: Cloud Infinite Description: Provides developers with intelligent processing services for images, videos, and other types of data.
  • Type: Cloud Storage Description: Storing images and improving their loading speed via CDN.
  • Type: Cloud Function Description: Detects image processing parameters and generates signatures for image processing to ensure the legitimacy of operations.

Permission Granting

Primary Account

Role NameAuthorization Policy NameRole TypeDescription
CI_QCSRoleQcloudAccessForCIRole, QcloudCOSDataFullControlService RoleCloud Infinite (CI) will access your Tencent Cloud resources, including reading, modifying, deleting, listing, etc. of COS data.
TCB_QcsRoleQcloudCIFullAccessService RoleCloudBase (TCB) will operate on your Cloud Infinite (CI) resources to facilitate your use of this service in extension capabilities.

Sub-account

If you want a sub-account to be able to use this extension, you need to grant the following permissions to the sub-account:

  • Policy: QcloudTCBFullAccess Description: Full read-write access permissions for CloudBase.
  • Policy: QcloudCIFullAccess Description: Full read-write access permissions for Cloud Infinite (CI).

Install Extension

You can install and manage extensions via the CloudBase Console.

Use Extension

! If you use this extension on a web website, first add the website domain as a security domain for the current environment in the CloudBase Console.

1. Install the extension SDK to your project

npm install --save @cloudbase/extension-ci@latest

2. Invoke the extension SDK

Invocation Parameters

NameTypeRequiredDescription
actionStringYesOperation type, pass: DetectType
cloudPathStringYesAbsolute path of the file, same as in tcb.uploadFile
operationsObjectYesProcessing parameters.

operations node content

NameTypeRequiredDescription
typeStringYesAudit types supported: porn (pornography detection), terrorist (terrorist content detection), politics (politically sensitive content detection), ads (advertising detection). Multiple detection types can be selected, e.g., porn, ads

Response

Parameter NameTypeDescription
RecognitionResultObjectContent recognition result

RecognitionResult node content:

Parameter NameTypeDescription
PornInfoObjectPornography moderation information
TerroristInfoObjectTerrorist content moderation information
PoliticsInfoObjectPolitically sensitive content moderation information
AdsInfoObjectAdvertising moderation information

The moderation information (PornInfo, TerroristInfo, PoliticsInfo, AdsInfo) contains the following content:

Parameter NameTypeDescription
CodeIntError code. 0 indicates success, other numbers correspond to specific errors. For details, see Error Codes
HitFlagIntHit status: 0 (not hit), 1 (hit), 2 (suspected)
ScoreIntModeration score: 0-60 (normal), 60-90 (suspected sensitive), 90-100 (confirmed sensitive)
LabelStringIdentified image labels

Invoke Example

Client Usage:

const extCi = require("@cloudbase/extension-ci");
const tcb = require("@cloudbase/js-sdk");

Usage in Cloud Functions:

const extCi = require("@cloudbase/extension-ci");
const tcb = require("@cloudbase/node-sdk");

You can choose to use it in [client] or [cloud functions] as needed, and then invoke it with the following code:

const app = tcb.init({
env: "Your Environment ID"
});

app.registerExtension(extCi);

async function demo() {
try {
const opts = {
type: "porn"
};
const res = await app.invokeExtension("CloudInfinite", {
action: "DetectType",
cloudPath: "ab.png", // Absolute path of the image to be analyzed, same as in tcb.uploadFile
operations: opts
});
console.log(JSON.stringify(res.data, null, 4));
} catch (err) {
console.log(JSON.stringify(err, null, 4));
}
}