Enhance Your Creativity with Composite Image Generation

26 Apr 2025
Enhance Your Creativity with Composite Image Generation

In today's digital landscape, the ability to create stunning visuals quickly and efficiently is essential for developers and designers alike. The "Meinamix Public" service offers advanced Cognitive Actions, including the powerful "Generate Composite Image" action. This action combines text-to-image and image-to-image generation processes, allowing users to create unique composite images with exceptional customization options. By leveraging this service, developers can significantly speed up their creative workflows, simplify image generation tasks, and produce high-quality outputs tailored to their specific needs.

Common use cases for the Generate Composite Image action include creating marketing visuals, designing artwork for social media, enhancing game graphics, or producing unique content for blogs and websites. Whether you are creating promotional material or simply experimenting with art, this action provides the tools you need to bring your ideas to life.

Prerequisites

To use the Generate Composite Image action, you will need a Cognitive Actions API key and a basic understanding of making API calls.

Generate Composite Image

The "Generate Composite Image" action is designed to create a composite image by utilizing advanced features such as face swapping, image restoration, and Controlnet processing. This action is particularly useful for developers looking to harness the power of AI to generate intricate visuals that require specific attributes and styles.

Input Requirements: The action accepts a comprehensive set of parameters within a structured request. Key inputs include:

  • prompt: A descriptive text guiding the image generation process (e.g., "masterpiece, best quality...").
  • faceImage: A URI pointing to an input face image for processing.
  • numOutputs: Specifies the number of images to generate (1-4).
  • targetWidth/Height: Defines the dimensions of the output image.
  • guidanceScale: A scale factor controlling the effect of the provided prompt.

Expected Output: The action returns an array of image URLs, each pointing to a generated composite image based on the provided inputs. For example:

[
  "https://assets.cognitiveactions.com/invocations/6b68b579-9a8b-4237-9972-c6d42c653e97/cad47993-5420-4a94-b777-dce02efe506b.png",
  "https://assets.cognitiveactions.com/invocations/6b68b579-9a8b-4237-9972-c6d42c653e97/784f014d-c9fb-4616-a49d-ee7728d88223.png"
]

Use Cases for this specific action:

  • Marketing Campaigns: Create eye-catching visuals for promotional materials that capture audience attention.
  • Artistic Projects: Generate unique artwork for portfolios or personal projects, allowing for experimentation with styles and techniques.
  • Social Media Content: Produce engaging images tailored to specific themes or trends, enhancing online presence.
  • Game Development: Design character visuals or backgrounds, utilizing face swapping and restoration for dynamic content.
import requests
import json

# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"

action_id = "75e26a7a-c973-4f35-9c00-ea415b7a7b8b" # Action ID for: Generate Composite Image

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "prompt": "masterpiece, best quality, <lora:frosted-style-richy-v1:1> frostedstyle, 1girl, solo, upper body, sunbeam, parted lips, blue lipstick, aqua hair, white eyes, outdoors, blue sky, sharp appearance, crystalline, frozen, ice",
  "aiRandom": "ai_random",
  "clipSkip": 2,
  "faceImage": "https://replicate.delivery/pbxt/K2vtBjh6mCvpSVJR9w74oV9u78DRKBYzTzWm6vipKGrAPF0i/999.png",
  "numOutputs": 2,
  "randomSeed": -1,
  "targetWidth": 599,
  "targetHeight": 900,
  "callbackSteps": 4,
  "guidanceScale": 6,
  "taskScheduler": "DPM++ SDE Karras",
  "controlNetType": "canny",
  "negativePrompt": "text, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, (holding object, holding), (low quality, worst quality:1.2), asymmetrical armor, undetailed face, nipples, NSFW, | bad-hands-5 EasynegativeV2 bad-hands-5 verybadimagenegative_v1.3, (worst quality, low quality:1.4), (malformed hands:1.4), (mutated fingers:1.4), text, signature, simple background EasynegativeV2, no human ears",
  "promptStrength": 0.6,
  "showSystemInfo": false,
  "swapFaceEnable": false,
  "imageResizeMode": "fill",
  "controlNetEnable": true,
  "faceEditorEnable": false,
  "cannyLowThreshold": 100,
  "loraModelExtraUrl": "https://civitai.com/models/228789/frosted-style-lora?modelVersionId=258193",
  "numInferenceSteps": 30,
  "restoreFaceEnable": false,
  "cannyHighThreshold": 200,
  "codeformerFidelity": 0.7,
  "faceEditorMaskBlur": 12,
  "faceEditorMaskSize": 6,
  "firebaseApiVersion": 4,
  "restoreFaceUpscale": 1,
  "crossAttentionScale": 0.5,
  "faceEditorStrength1": 0.4,
  "faceEditorStrength2": 0.05,
  "imageGenerationType": "txt2img",
  "restoreFaceUpsample": false,
  "faceEditorConfidence": 0.97,
  "controlGuidanceEndPoint": 1,
  "controlGuidanceStartPoint": 0,
  "controlNetConditioningScale": 0.55,
  "restoreFaceBackgroundEnhance": false
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json",
    # Add any other required headers for the Cognitive Actions API
}

# Prepare the request body for the hypothetical execution endpoint
request_body = {
    "action_id": action_id,
    "inputs": payload
}

print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json=request_body
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully. Result:")
    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 (non-JSON): {e.response.text}")
    print("------------------------------------------------")

Conclusion

The Generate Composite Image action from Meinamix Public empowers developers to create customized and visually appealing images with minimal effort. Its versatility makes it suitable for a wide range of applications, ensuring that users can meet their creative needs efficiently. To get started, integrate this action into your projects and explore the myriad possibilities it offers for enhancing your visual content.