Human to anime style

Updated at:

The human to anime style feature transforms a portrait image into various cartoon-style images. This topic provides sample code in popular programming languages for this feature.

Note
  • For real-time assistance, start an online consultation.

  • If you have questions about API access or usage for the Alibaba Cloud Vision AI Platform, join our DingTalk group (ID: 23109592) to contact us.

Overview

For a feature overview and a detailed description of its request parameters, see Human to anime style.

SDK installation

For information about the SDK dependencies for popular programming languages, see SDK Overview.

Configure environment variables

Configure the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables.

Important
  • An Alibaba Cloud account has full access to all API operations. We recommend that you use a RAM user for API calls or routine O&M. For more information, see Create a RAM user.

  • Do not save your AccessKey ID or AccessKey Secret in project code. Otherwise, the AccessKey pair may be leaked and the security of all resources in your account may be compromised.

  • Configure environment variables on Linux and macOS

    1. Open a terminal in IntelliJ IDEA.

    2. Run the following commands to configure the environment variables.

      Replace <access_key_id> with the AccessKey ID of your RAM user and <access_key_secret> with the AccessKey Secret of your RAM user. If you need to configure more permissions, see Control access permissions using a RAM policy.

      export ALIBABA_CLOUD_ACCESS_KEY_ID=<access_key_id>
      export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<access_key_secret>
  • Configure environment variables on Windows

    Create a new environment variable file, add the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET, and set them to the AccessKey ID and AccessKey Secret that you have prepared. Then, restart the Windows operating system. The following example uses Windows 10.

    1. Open File Explorer, right-click This PC, and then select Properties.

    2. In the left-side navigation pane, click Advanced system settings.

    3. On the Advanced tab of the System Properties dialog box, click Environment Variables.

    4. In the Environment Variables dialog box, click New.

    5. In the New System Variable dialog box, add the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET, and set them to the AccessKey ID and AccessKey Secret that you have prepared.

    6. Restart the Windows operating system for the configurations to take effect.

Sample code

File in an OSS bucket (Shanghai)

/*
Add the dependency.
The minimum required SDK version for facebody20191230 is 3.0.7.
For the latest SDK version, see: https://mvnrepository.com/artifact/com.aliyun/facebody20191230
<!-- https://mvnrepository.com/artifact/com.aliyun/facebody20191230 -->
<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>facebody20191230</artifactId>
    <version>${aliyun.facebody.version}</version>
</dependency>
*/

import com.aliyun.facebody20191230.models.GenerateHumanAnimeStyleResponse;
import com.aliyun.tea.*;

public class GenerateHumanAnimeStyle {

    public static com.aliyun.facebody20191230.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        /*
          Initialize the configuration object com.aliyun.teaopenapi.models.Config.
          The Config object stores configurations such as your AccessKey ID, AccessKey Secret, and endpoint.
         */
         com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                .setAccessKeyId(accessKeyId)
                .setAccessKeySecret(accessKeySecret);
        // The endpoint of the service.
        config.endpoint = "facebody.cn-shanghai.aliyuncs.com";
        return new com.aliyun.facebody20191230.Client(config);
    }

    public static void main(String[] args) throws Exception {
        // For information about how to create an AccessKey pair, see https://help.aliyun.com/document_detail/175144.html.
        // If you use an AccessKey pair of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
        // This code reads the AccessKey ID and AccessKey Secret from environment variables. Ensure these variables are configured before you run the code.
        String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
        String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"); 
        com.aliyun.facebody20191230.Client client = GenerateHumanAnimeStyle.createClient(accessKeyId, accessKeySecret);
        com.aliyun.facebody20191230.models.GenerateHumanAnimeStyleRequest generateHumanAnimeStyleRequest = new com.aliyun.facebody20191230.models.GenerateHumanAnimeStyleRequest()
                .setImageURL("http://invi-label.oss-cn-shanghai.aliyuncs.com/label/temp/cartoon/test_data/c1.jpg")
                .setAlgoType("anime");
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            // Note: The response needs to be processed based on your business logic.
            GenerateHumanAnimeStyleResponse response = client.generateHumanAnimeStyleWithOptions(generateHumanAnimeStyleRequest, runtime);
            // Print the full response.
            System.out.println(com.aliyun.teautil.Common.toJSONString(TeaModel.buildMap(response)));
        } catch (TeaException error) {
            // Print the full error message.
            System.out.println(com.aliyun.teautil.Common.toJSONString(error));
            // Print a specific field.
            System.out.println(error.getCode());
        }
    }
}
# -*- coding: utf-8 -*-
# Import the dependency.
# The minimum required SDK version for facebody20191230 is 4.0.8.
# You can reference the latest SDK version at: https://pypi.org/project/alibabacloud-facebody20191230/
# pip install alibabacloud_facebody20191230

import os
from alibabacloud_facebody20191230.client import Client
from alibabacloud_facebody20191230.models import GenerateHumanAnimeStyleRequest
from alibabacloud_tea_openapi.models import Config
from alibabacloud_tea_util.models import RuntimeOptions

config = Config(
  # For information about how to create an AccessKey pair, see https://help.aliyun.com/document_detail/175144.html.
  # If you use an AccessKey pair of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
  # This code reads the AccessKey ID and AccessKey Secret from environment variables. Ensure these variables are configured before you run the code.
  access_key_id=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID'),
  access_key_secret=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET'),
  # The endpoint of the service.
  endpoint='facebody.cn-shanghai.aliyuncs.com',
  # The region ID that corresponds to the endpoint.
  region_id='cn-shanghai'
)
generate_human_anime_style_request = GenerateHumanAnimeStyleRequest(
     image_url='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/GenerateHumanAnimeStyle/GenerateHumanAnimeStyle1.png',
     algo_type='anime'
)
runtime = RuntimeOptions()
try:
  # Initialize the client.
  client = Client(config)
  response = client.generate_human_anime_style_with_options(generate_human_anime_style_request, runtime)
  # Print the full response.
  print(response.body)
except Exception as error:
  # Print the full error message.
  print(error)
  # Print a specific field.
  print(error.code)
  # Tip: You can use error.__dict__ to view all attributes of the error.
<?php

// Install the dependency.
// The minimum required SDK version for facebody-20191230 is 3.0.8.
// You can reference the latest SDK version at: https://packagist.org/packages/alibabacloud/facebody-20191230  
// composer require alibabacloud/facebody-20191230

use AlibabaCloud\SDK\Facebody\V20191230\Facebody;
use \Exception;
use AlibabaCloud\Tea\Utils\Utils;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Facebody\V20191230\Models\GenerateHumanAnimeStyleRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;

class GenerateHumanAnimeStyle {

    /**
     * Use your AccessKey ID and AccessKey Secret to initialize the client.
     * @param string $accessKeyId
     * @param string $accessKeySecret
     * @return Facebody Client
     */
    public static function createClient($accessKeyId, $accessKeySecret){
        // Initialize the configuration object Darabonba\OpenApi\Models\Config.
        // The Config object stores configurations such as your AccessKey ID, AccessKey Secret, and endpoint.
        $config = new Config([
            "accessKeyId" => $accessKeyId,
            "accessKeySecret" => $accessKeySecret
        ]);
        // The endpoint of the service.
        $config->endpoint = "facebody.cn-shanghai.aliyuncs.com";
        return new Facebody($config);
    }

    /**
     * @param string[] $args
     * @return void
     */
    public static function main($args){
        // For information about how to create an AccessKey pair, see https://help.aliyun.com/document_detail/175144.html.
        // If you use an AccessKey pair of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
        // This code reads the AccessKey ID and AccessKey Secret from environment variables. Ensure these variables are configured before you run the code.
        $accessKeyId = getenv('ALIBABA_CLOUD_ACCESS_KEY_ID');
        $accessKeySecret = getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET'); 
        $client = self::createClient($accessKeyId, $accessKeySecret);
        $generateHumanAnimeStyleRequest = new GenerateHumanAnimeStyleRequest([
            "imageURL" => "http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/GenerateHumanAnimeStyle/GenerateHumanAnimeStyle10.png",
            "algoType" => "anime"
        ]);
        $runtime = new RuntimeOptions([]);
        try {
            $resp = $client->generateHumanAnimeStyleWithOptions($generateHumanAnimeStyleRequest, $runtime);
            # Print the full response.
            echo Utils::toJSONString($resp->body);
        } catch (Exception $exception) {
            # Print the full error message.
            echo Utils::toJSONString($exception);
            # Print a specific field.
            echo $exception->getCode();
        }
    }
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
    require_once $path;
}
// The `$argv` parameter is a reserved array for input parameters, is not used in this example, and does not need to be modified.
GenerateHumanAnimeStyle::main(array_slice($argv, 1));
// Install the dependency.
//npm install @alicloud/facebody20191230
// The minimum required SDK version for facebody20191230 is 4.0.7.
// You can reference the latest SDK version at: https://npmjs.com/package/@alicloud/facebody20191230
const FacebodyClient = require('@alicloud/facebody20191230');
const OpenapiClient = require('@alicloud/openapi-client');
const TeaUtil = require('@alicloud/tea-util');

let config = new OpenapiClient.Config({
  // For information about how to create an AccessKey pair, see https://help.aliyun.com/document_detail/175144.html.
  // If you use an AccessKey pair of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
  // This code reads the AccessKey ID and AccessKey Secret from environment variables. Ensure these variables are configured before you run the code.
  accessKeyId: process.env.ALIBABA_CLOUD_ACCESS_KEY_ID,   
  accessKeySecret: process.env.ALIBABA_CLOUD_ACCESS_KEY_SECRET
});
// The endpoint of the service.
config.endpoint = `facebody.cn-shanghai.aliyuncs.com`;
const client = new FacebodyClient.default(config);
let generateHumanAnimeStyleRequest = new FacebodyClient.GenerateHumanAnimeStyleRequest({
  imageURL: "http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/GenerateHumanAnimeStyle/GenerateHumanAnimeStyle8.png",
});
let runtime = new TeaUtil.RuntimeOptions({ });
client.generateHumanAnimeStyleWithOptions(generateHumanAnimeStyleRequest, runtime)
  .then(function(generateHumanAnimeStyleResponse) {
    // Print the full response.
    console.log(generateHumanAnimeStyleResponse);
    // Print a specific field.
    console.log(generateHumanAnimeStyleResponse.body.data);
  }, function(error) {
    // Print the full error message.
    console.log(error);
    // Print a specific field.
    console.log(error.data.Code);
  })
/**
The minimum required SDK version for facebody-20191230 is 4.0.7.
You can reference the latest SDK version at: https://pkg.go.dev/github.com/alibabacloud-go/facebody-20191230/v4
This depends on github.com/alibabacloud-go/facebody-20191230.
We recommend that you run the 'go mod tidy' command to install the dependencies.
*/

package main

import (
	"fmt"
	openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
	facebody20191230 "github.com/alibabacloud-go/facebody-20191230/v4/client"
	util "github.com/alibabacloud-go/tea-utils/v2/service"
	"github.com/alibabacloud-go/tea/tea"
	"os"
)

func main() {
  // For information about how to create an AccessKey pair, see https://help.aliyun.com/document_detail/175144.html.
  // If you use an AccessKey pair of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
  // This code reads the AccessKey ID and AccessKey Secret from environment variables. Ensure these variables are configured before you run the code.
  accessKeyId := os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
	accessKeySecret := os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
  // Initialize the &openapi.Config object. The Config object stores configurations such as your AccessKey ID, AccessKey Secret, and endpoint.
	config := &openapi.Config{
		AccessKeyId: tea.String(accessKeyId),
		AccessKeySecret: tea.String(accessKeySecret),
	}
	// The endpoint of the service.
	config.Endpoint = tea.String("facebody.cn-shanghai.aliyuncs.com")
	client, err := facebody20191230.NewClient(config)
	if err != nil {
		fmt.Println(err.Error())
	}

	generateHumanAnimeStyleRequest := &facebody20191230.GenerateHumanAnimeStyleRequest{
		ImageURL: tea.String("http://invi-label.oss-cn-shanghai.aliyuncs.com/label/temp/cartoon/test_data/c1.jpg"),
	}
	runtime := &util.RuntimeOptions{}
	generateHumanAnimeStyleResponse, _err := client.GenerateHumanAnimeStyleWithOptions(generateHumanAnimeStyleRequest, runtime)
	if _err != nil {
		fmt.Println(_err.Error())
	} else {
		// Print the full response.
		fmt.Println(generateHumanAnimeStyleResponse)
		// Print a specific field.
		fmt.Println(generateHumanAnimeStyleResponse.Body.Data)
	}
}
// Install the dependency.
// dotnet add package AlibabaCloud.SDK.Facebody20191230
// The minimum required SDK version for facebody20191230 is 3.0.7.
// You can reference the latest SDK version at: https://nuget.org/packages/AlibabaCloud.SDK.Facebody20191230
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using AlibabaCloud.SDK.Facebody20191230.Models;
using Tea;
using Tea.Utils;

namespace AlibabaCloud.SDK.Sample
{
    public class Sample
    {
        /**
            * Use your AccessKey ID and AccessKey Secret to initialize the client.
            * @param accessKeyId
            * @param accessKeySecret
            * @return Client
            * @throws Exception
        */
        public static AlibabaCloud.SDK.Facebody20191230.Client CreateClient(string accessKeyId, string accessKeySecret)
        {
            AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
            {
                AccessKeyId = accessKeyId,
                AccessKeySecret = accessKeySecret,
            };
            // The endpoint of the service.
            config.Endpoint = "facebody.cn-shanghai.aliyuncs.com";
            return new AlibabaCloud.SDK.Facebody20191230.Client(config);
        }
        public static void Main(string[] args)
        {
            // For information about how to create an AccessKey pair, see https://help.aliyun.com/document_detail/175144.html.
            // If you use an AccessKey pair of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
            // This code reads the AccessKey ID and AccessKey Secret from environment variables. Ensure these variables are configured before you run the code.
            AlibabaCloud.SDK.Facebody20191230.Client client = CreateClient(System.Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
            AlibabaCloud.SDK.Facebody20191230.Models.GenerateHumanAnimeStyleRequest generateHumanAnimeStyleRequest = new AlibabaCloud.SDK.Facebody20191230.Models.GenerateHumanAnimeStyleRequest
            {
                ImageURL = "http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/GenerateHumanAnimeStyle/GenerateHumanAnimeStyle8.png",
            };
            AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
            try
            {
                AlibabaCloud.SDK.Facebody20191230.Models.GenerateHumanAnimeStyleResponse generateHumanAnimeStyleResponse = client.GenerateHumanAnimeStyleWithOptions(generateHumanAnimeStyleRequest, runtime);
                // Print the full response.
                Console.WriteLine(AlibabaCloud.TeaUtil.Common.ToJSONString(generateHumanAnimeStyleResponse.Body));
                // Print a specific field.
                Console.WriteLine(AlibabaCloud.TeaUtil.Common.ToJSONString(generateHumanAnimeStyleResponse.Body.Data));
            }
            catch (TeaException error)
            {
                // Prints the error message.
                Console.WriteLine(AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message));
            }
            catch (Exception _error)
            {
                TeaException error = new TeaException(new Dictionary<string, object>
              {
                { "message", _error.Message }
              });
                // Prints the error message.
                Console.WriteLine(AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message));
            }
        }
    }
}

Local file or public URL

/*
Add the dependency.
The minimum required SDK version for facebody20191230 is 3.0.7.
You can reference the latest SDK version at: https://mvnrepository.com/artifact/com.aliyun/facebody20191230
<!-- https://mvnrepository.com/artifact/com.aliyun/facebody20191230 -->
<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>facebody20191230</artifactId>
    <version>${aliyun.facebody.version}</version>
</dependency>
*/

import com.aliyun.facebody20191230.models.GenerateHumanAnimeStyleResponse;
import com.aliyun.tea.TeaException;
import com.aliyun.tea.TeaModel;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.URL;

public class GenerateHumanAnimeStyle {

    public static com.aliyun.facebody20191230.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        /*
          Initialize the configuration object com.aliyun.teaopenapi.models.Config.
          The Config object stores configurations such as your AccessKey ID, AccessKey Secret, and endpoint.
         */
         com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                .setAccessKeyId(accessKeyId)
                .setAccessKeySecret(accessKeySecret);
        // The endpoint of the service.
        config.endpoint = "facebody.cn-shanghai.aliyuncs.com";
        return new com.aliyun.facebody20191230.Client(config);
    }

    public static void main(String[] args) throws Exception {
        // For information about how to create an AccessKey pair, see https://help.aliyun.com/document_detail/175144.html.
        // If you use an AccessKey pair of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
        // This code reads the AccessKey ID and AccessKey Secret from environment variables. Ensure these variables are configured before you run the code.
        String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
        String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"); 
        com.aliyun.facebody20191230.Client client = GenerateHumanAnimeStyle.createClient(accessKeyId, accessKeySecret);
        // Scenario 1: Use a local file.
        //InputStream inputStream = new FileInputStream(new File("/tmp/GenerateHumanAnimeStyle1.jpg"));
        // Scenario 2: Use a publicly accessible URL.
        URL url = new URL("http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/GenerateHumanAnimeStyle/GenerateHumanAnimeStyle8.png");
        InputStream inputStream = url.openConnection().getInputStream();
        com.aliyun.facebody20191230.models.GenerateHumanAnimeStyleAdvanceRequest generateHumanAnimeStyleAdvanceRequest = new com.aliyun.facebody20191230.models.GenerateHumanAnimeStyleAdvanceRequest()
                .setImageURLObject(inputStream)
                .setAlgoType("anime");
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            // Note: The response needs to be processed based on your business logic.
            GenerateHumanAnimeStyleResponse response = client.generateHumanAnimeStyleAdvance(generateHumanAnimeStyleAdvanceRequest, runtime);
            // Print the full response.
            System.out.println(com.aliyun.teautil.Common.toJSONString(TeaModel.buildMap(response)));
        } catch (TeaException error) {
            // Print the full error message.
            System.out.println(com.aliyun.teautil.Common.toJSONString(error));
            // Print a specific field.
            System.out.println(error.getCode());
        }
    }
}
# -*- coding: utf-8 -*-
# Import the dependency.
# The minimum required SDK version for facebody20191230 is 4.0.8.
# You can reference the latest SDK version at: https://pypi.org/project/alibabacloud-facebody20191230/
# pip install alibabacloud_facebody20191230

import os
import io
from urllib.request import urlopen
from alibabacloud_facebody20191230.client import Client
from alibabacloud_facebody20191230.models import GenerateHumanAnimeStyleAdvanceRequest
from alibabacloud_tea_openapi.models import Config
from alibabacloud_tea_util.models import RuntimeOptions

config = Config(
  # For information about how to create an AccessKey pair, see https://help.aliyun.com/document_detail/175144.html.
  # If you use an AccessKey pair of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
  # This code reads the AccessKey ID and AccessKey Secret from environment variables. Ensure these variables are configured before you run the code.
  access_key_id=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID'),
  access_key_secret=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET'),
  # The endpoint of the service.
  endpoint='facebody.cn-shanghai.aliyuncs.com',
  # The region ID that corresponds to the endpoint.
  region_id='cn-shanghai'
)
generate_human_anime_style_request = GenerateHumanAnimeStyleAdvanceRequest()
# Scenario 1: Use a local file.
#stream = open(r'/tmp/GenerateHumanAnimeStyle8.png', 'rb')
#generate_human_anime_style_request.image_urlobject = stream

# Scenario 2: Use a publicly accessible URL.
url = 'http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/GenerateHumanAnimeStyle/GenerateHumanAnimeStyle8.png'
img = urlopen(url).read()
generate_human_anime_style_request.image_urlobject = io.BytesIO(img)
generate_human_anime_style_request.algo_type = 'anime'

runtime = RuntimeOptions()
try:
  # Initialize the client.
  client = Client(config)
  response = client.generate_human_anime_style_advance(generate_human_anime_style_request, runtime)
  # Print the full response.
  print(response.body)
except Exception as error:
  # Print the full error message.
  print(error)
  # Print a specific field.
  print(error.code)
  # Tip: You can use error.__dict__ to view all attributes of the error.
<?php

// Install the dependency.
// The minimum required SDK version for facebody-20191230 is 3.0.8.
// You can reference the latest SDK version at: https://packagist.org/packages/alibabacloud/facebody-20191230    
// composer require alibabacloud/facebody-20191230

use AlibabaCloud\SDK\Facebody\V20191230\Facebody;
use \Exception;
use AlibabaCloud\Tea\Utils\Utils;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Facebody\V20191230\Models\GenerateHumanAnimeStyleAdvanceRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use GuzzleHttp\Psr7\Stream;

class GenerateHumanAnimeStyleAdvance {

    /**
     * Use your AccessKey ID and AccessKey Secret to initialize the client.
     * @param string $accessKeyId
     * @param string $accessKeySecret
     * @return Facebody Client
     */
    public static function createClient($accessKeyId, $accessKeySecret){
        // Initialize the configuration object Darabonba\OpenApi\Models\Config.
        // The Config object stores configurations such as your AccessKey ID, AccessKey Secret, and endpoint.
        $config = new Config([
            "accessKeyId" => $accessKeyId,
            "accessKeySecret" => $accessKeySecret
        ]);
        // The endpoint of the service.
        $config->endpoint = "facebody.cn-shanghai.aliyuncs.com";
        return new Facebody($config);
    }

    /**
     * @param string[] $args
     * @return void
     */
    public static function main($args){
        // For information about how to create an AccessKey pair, see https://help.aliyun.com/document_detail/175144.html.
        // If you use an AccessKey pair of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
		// This code reads the AccessKey ID and AccessKey Secret from environment variables. Ensure these variables are configured before you run the code.
		$accessKeyId = getenv('ALIBABA_CLOUD_ACCESS_KEY_ID');
		$accessKeySecret = getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET'); 
        $client = self::createClient($accessKeyId, $accessKeySecret);
        // Scenario 1: Use a local file.
        //$file = fopen('/tmp/GenerateHumanAnimeStyle8.png', 'rb');
        //$stream = new Stream($file);
        // Scenario 2: Use a publicly accessible URL.
        $file = fopen('http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/GenerateHumanAnimeStyle/GenerateHumanAnimeStyle8.png', 'rb');
        $stream = new Stream($file);
        $generateHumanAnimeStyleAdvanceRequest = new GenerateHumanAnimeStyleAdvanceRequest([
            "imageURLObject" => $stream,
            "algoType" => "anime"
        ]);
        $runtime = new RuntimeOptions([]);
        try {
            $resp = $client->generateHumanAnimeStyleAdvance($generateHumanAnimeStyleAdvanceRequest, $runtime);
            # Print the full response.
            echo Utils::toJSONString($resp->body);
        } catch (Exception $exception) {
            # Print the full error message.
            echo Utils::toJSONString($exception);
            # Print a specific field.
            echo $exception->getCode();
        }
    }
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
    require_once $path;
}
// The `$argv` parameter is a reserved array for input parameters, is not used in this example, and does not need to be modified.
GenerateHumanAnimeStyleAdvance::main(array_slice($argv, 1));
// Install the dependency.
//npm install @alicloud/facebody20191230
// The minimum required SDK version for facebody20191230 is 4.0.7.
// You can reference the latest SDK version at: https://npmjs.com/package/@alicloud/facebody20191230
const FacebodyClient = require('@alicloud/facebody20191230');
const OpenapiClient = require('@alicloud/openapi-client');
const TeaUtil = require('@alicloud/tea-util');
const fs = require('fs');
const http = require('http');
const https = require('https');

let config = new OpenapiClient.Config({
  // For information about how to create an AccessKey pair, see https://help.aliyun.com/document_detail/175144.html.
  // If you use an AccessKey pair of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
  // This code reads the AccessKey ID and AccessKey Secret from environment variables. Ensure these variables are configured before you run the code.
  accessKeyId: process.env.ALIBABA_CLOUD_ACCESS_KEY_ID,   
  accessKeySecret: process.env.ALIBABA_CLOUD_ACCESS_KEY_SECRET
});
// The endpoint of the service.
config.endpoint = `facebody.cn-shanghai.aliyuncs.com`;
const client = new FacebodyClient.default(config);
const getResponse = function (httpClient, url) {
  return new Promise((resolve, reject) => {
    httpClient.get(url, function (response) {
      resolve(response);
    })
  })
}
const request = async function () {
  try {
    let generateHumanAnimeStyleAdvanceRequest = new FacebodyClient.GenerateHumanAnimeStyleAdvanceRequest();
    // Scenario 1: Use a local file.
    // const fileStream = fs.createReadStream('/tmp/GenerateHumanAnimeStyle8.png');
    // generateHumanAnimeStyleAdvanceRequest.imageURLObject = fileStream;
    // Scenario 2: Use a publicly accessible URL.
    const url = new URL('http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/GenerateHumanAnimeStyle/GenerateHumanAnimeStyle8.png');
    const httpClient = (url.protocol == "https:") ? https : http;
    generateHumanAnimeStyleAdvanceRequest.imageURLObject = await getResponse(httpClient, url);
    let runtime = new TeaUtil.RuntimeOptions({});
    client.generateHumanAnimeStyleAdvance(generateHumanAnimeStyleAdvanceRequest, runtime)
      .then(function (generateHumanAnimeStyleResponse) {
        // Print the full response.
        console.log(generateHumanAnimeStyleResponse);
        // Print a specific field.
        console.log(generateHumanAnimeStyleResponse.body.data);
      }, function (error) {
        // Print the full error message.
        console.log(error);
        // Print a specific field.
        console.log(error.data.Code);
      })
  } catch (error) {
    console.log(error);
  }
}();
/**
The minimum required SDK version for facebody-20191230 is 4.0.7.
You can reference the latest SDK version at: https://pkg.go.dev/github.com/alibabacloud-go/facebody-20191230/v4
This depends on github.com/alibabacloud-go/facebody-20191230.
We recommend that you run the 'go mod tidy' command to install the dependencies.
*/

package main

import (
	"fmt"
	openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
	facebody20191230 "github.com/alibabacloud-go/facebody-20191230/v4/client"
	util "github.com/alibabacloud-go/tea-utils/v2/service"
	"github.com/alibabacloud-go/tea/tea"
	"net/http"
	"os"
)

func main() {
  // For information about how to create an AccessKey pair, see https://help.aliyun.com/document_detail/175144.html.
  // If you use an AccessKey pair of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
  // This code reads the AccessKey ID and AccessKey Secret from environment variables. Ensure these variables are configured before you run the code.
  accessKeyId := os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
	accessKeySecret := os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
  // Initialize the &openapi.Config object. The Config object stores configurations such as your AccessKey ID, AccessKey Secret, and endpoint.
	config := &openapi.Config{
		AccessKeyId: tea.String(accessKeyId),
		AccessKeySecret: tea.String(accessKeySecret),
	}
	// The endpoint of the service.
	config.Endpoint = tea.String("facebody.cn-shanghai.aliyuncs.com")
	client, err := facebody20191230.NewClient(config)
	if err != nil {
		fmt.Println(err.Error())
	}

	// Scenario 1: Use a local file.
	//file, err := os.Open("/tmp/GenerateHumanAnimeStyle1.jpg")
	//if err != nil {
	//	fmt.Println("can not open file", err)
	//}
	//generateHumanAnimeStyleAdvanceRequest := &facebody20191230.GenerateHumanAnimeStyleAdvanceRequest{
	//	ImageURLObject: file,
	//}
	// Scenario 2: Use a publicly accessible URL.
	httpClient := http.Client{}
	file, _ := httpClient.Get("http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/GenerateHumanAnimeStyle/GenerateHumanAnimeStyle8.png")
	generateHumanAnimeStyleAdvanceRequest := &facebody20191230.GenerateHumanAnimeStyleAdvanceRequest{
		ImageURLObject: file.Body,
	}
	runtime := &util.RuntimeOptions{}
	generateHumanAnimeStyleResponse, _err := client.GenerateHumanAnimeStyleAdvance(generateHumanAnimeStyleAdvanceRequest, runtime)
	if _err != nil {
		fmt.Println(_err.Error())
	} else {
		// Print the full response.
		fmt.Println(generateHumanAnimeStyleResponse)
		// Print a specific field.
		fmt.Println(generateHumanAnimeStyleResponse.Body.Data)
	}
}
// Install the dependency.
// dotnet add package AlibabaCloud.SDK.Facebody20191230
// The minimum required SDK version for facebody20191230 is 3.0.7.
// You can reference the latest SDK version at: https://nuget.org/packages/AlibabaCloud.SDK.Facebody20191230
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Threading.Tasks;
using AlibabaCloud.SDK.Facebody20191230.Models;
using Tea;
using Tea.Utils;

namespace AlibabaCloud.SDK.Sample
{
    public class Sample
    {
        /**
            * Use your AccessKey ID and AccessKey Secret to initialize the client.
            * @param accessKeyId
            * @param accessKeySecret
            * @return Client
            * @throws Exception
        */
        public static AlibabaCloud.SDK.Facebody20191230.Client CreateClient(string accessKeyId, string accessKeySecret)
        {
            AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
            {
                AccessKeyId = accessKeyId,
                AccessKeySecret = accessKeySecret,
            };
            // The endpoint of the service.
            config.Endpoint = "facebody.cn-shanghai.aliyuncs.com";
            return new AlibabaCloud.SDK.Facebody20191230.Client(config);
        }
        public static void Main(string[] args)
        {
            // For information about how to create an AccessKey pair, see https://help.aliyun.com/document_detail/175144.html.
            // If you use an AccessKey pair of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
            // This code reads the AccessKey ID and AccessKey Secret from environment variables. Ensure these variables are configured before you run the code.
            AlibabaCloud.SDK.Facebody20191230.Client client = CreateClient(System.Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
            AlibabaCloud.SDK.Facebody20191230.Models.GenerateHumanAnimeStyleAdvanceRequest generateHumanAnimeStyleAdvanceRequest = new AlibabaCloud.SDK.Facebody20191230.Models.GenerateHumanAnimeStyleAdvanceRequest
            ();
            // Scenario 1: Use a local file.
            System.IO.StreamReader file = new System.IO.StreamReader(@"/tmp/GenerateHumanAnimeStyle8.png");
            generateHumanAnimeStyleAdvanceRequest.ImageURLObject = file.BaseStream;

            // Scenario 2: Use a publicly accessible URL.
            //HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/GenerateHumanAnimeStyle/GenerateHumanAnimeStyle8.png");
            //WebResponse response = request.GetResponse();
            //Stream stream = response.GetResponseStream();
            //generateHumanAnimeStyleAdvanceRequest.ImageURLObject = stream;
            AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
            try
            {
                AlibabaCloud.SDK.Facebody20191230.Models.GenerateHumanAnimeStyleResponse generateHumanAnimeStyleResponse = client.GenerateHumanAnimeStyleAdvance(generateHumanAnimeStyleAdvanceRequest, runtime);
                // Print the full response.
                Console.WriteLine(AlibabaCloud.TeaUtil.Common.ToJSONString(generateHumanAnimeStyleResponse.Body));
                // Print a specific field.
                Console.WriteLine(AlibabaCloud.TeaUtil.Common.ToJSONString(generateHumanAnimeStyleResponse.Body.Data));
            }
            catch (TeaException error)
            {
                // Prints the error message.
                Console.WriteLine(AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message));
            }
            catch (Exception _error)
            {
                TeaException error = new TeaException(new Dictionary<string, object>
              {
                { "message", _error.Message }
              });
                // Prints the error message.
                Console.WriteLine(AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message));
            }
        }
    }
}