Create Stunning Composite Images with the Blend Images Cognitive Actions

25 Apr 2025
Create Stunning Composite Images with the Blend Images Cognitive Actions

In the realm of image processing, combining visuals to create unique artistic representations is a captivating endeavor. The Blend Images Cognitive Actions, powered by the Kandinsky 2.2 blending pipeline, provide developers with the ability to generate high-quality composite images. By leveraging two input images alongside a user-defined prompt, these actions simplify the creation of visually engaging content.

Prerequisites

Before diving into the integration of these Cognitive Actions, ensure you have the following:

  • An API key for accessing the Cognitive Actions platform.
  • Basic knowledge of making HTTP requests and handling JSON data.
  • Familiarity with Python programming can be helpful for implementing the provided examples.

Authentication typically involves passing your API key in the request headers, allowing you to securely access the action's functionalities.

Cognitive Actions Overview

Blend Images Using Kandinsky 2.2

This action enables the blending of two images based on a specified textual prompt, resulting in a new composite image. The Kandinsky 2.2 blending pipeline is designed to produce high-quality outputs that reflect the user's creative vision.

Input

The Blend Images Using Kandinsky 2.2 action requires the following fields:

  • userPrompt (required): A brief textual description of the desired image outcome.
  • inputImageOne (required): The URI for the first input image, which should be a valid and accessible URL.
  • inputImageTwo (required): The URI for the second input image, also requiring a valid URL.

Example Input:

{
  "userPrompt": "A deer shaped clock",
  "inputImageOne": "https://replicate.delivery/pbxt/JYUwgFNQbajoEQxvkJIPjDfIpE5Pj51iSfeU8CaYe1896Hyk/generatedimg_4_43531b30-b813-4226-9d5a-a80b5a29f613_1695126618.png",
  "inputImageTwo": "https://replicate.delivery/pbxt/JYUwgCRwYFmMbVAK0RmU5ftY6zg86x6zjTrLG9Bq3abzB6Mw/generatedimg_2_466bb97d-67eb-406a-8a20-2aeb975ea45c_1695134551.png"
}

Output

Upon successfully blending the images, the action returns a URI to the newly created composite image. The output typically looks like this:

Example Output:

https://assets.cognitiveactions.com/invocations/a684b735-b9b7-4b7a-9e19-a76f9e350167/40bf625e-928f-4851-9d18-a0463c5a107e.png

Conceptual Usage Example (Python)

Here’s a conceptual example of how you might call the Blend Images Using Kandinsky 2.2 action using Python.

import requests
import json

# Replace with your Cognitive Actions API key and endpoint
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"  # Hypothetical endpoint

action_id = "31519bb0-280e-4cff-a930-650a16f5868c"  # Action ID for Blend Images Using Kandinsky 2.2

# Construct the input payload based on the action's requirements
payload = {
    "userPrompt": "A deer shaped clock",
    "inputImageOne": "https://replicate.delivery/pbxt/JYUwgFNQbajoEQxvkJIPjDfIpE5Pj51iSfeU8CaYe1896Hyk/generatedimg_4_43531b30-b813-4226-9d5a-a80b5a29f613_1695126618.png",
    "inputImageTwo": "https://replicate.delivery/pbxt/JYUwgCRwYFmMbVAK0RmU5ftY6zg86x6zjTrLG9Bq3abzB6Mw/generatedimg_2_466bb97d-67eb-406a-8a20-2aeb975ea45c_1695134551.png"
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json"
}

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json={"action_id": action_id, "inputs": payload}  # Hypothetical structure
    )
    response.raise_for_status()  # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully:")
    print(json.dumps(result, indent=2))

except requests.exceptions.RequestException as e:
    print(f"Error executing action {action_id}: {e}")
    if e.response is not None:
        print(f"Response status: {e.response.status_code}")
        try:
            print(f"Response body: {e.response.json()}")
        except json.JSONDecodeError:
            print(f"Response body: {e.response.text}")

In this code snippet, you’ll need to replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The input payload is constructed using the required fields, and the response is handled gracefully. This example illustrates a basic structure for invoking the blending action and retrieving the composite image URL.

Conclusion

The Blend Images Using Kandinsky 2.2 Cognitive Action provides developers with a powerful tool for creating visually captivating composite images. By simply combining two images with a user-defined prompt, you can harness the capabilities of advanced image processing without needing extensive expertise.

Explore the potential use cases, such as generating content for social media, enhancing creative projects, or making unique art pieces. Start integrating these actions into your applications and transform your creative visions into reality!