Create Stunning Custom Images Effortlessly with Krameran

25 Apr 2025
Create Stunning Custom Images Effortlessly with Krameran

Krameran offers powerful Cognitive Actions that enable developers to generate custom images tailored to specific needs. This service simplifies the process of image creation, allowing users to produce high-quality visuals based on detailed prompts, while also providing flexibility in settings such as model selection, output quality, and processing speed. By leveraging Krameran, developers can create unique images for applications ranging from marketing materials to personalized content creation.

Imagine needing an eye-catching image for a blog post or social media campaign. With Krameran, you can quickly generate visuals that align perfectly with your vision, saving time and resources. The capability to customize images with various parameters, including inpainting and LoRA weights, makes it an invaluable tool for developers seeking to enhance their projects with visually compelling elements.

Prerequisites

To get started with Krameran's Cognitive Actions, you'll need an API key and a basic understanding of making API calls.

Generate Custom Images

The "Generate Custom Images" action allows you to create images based on custom prompts with a variety of settings to refine the output. This action addresses the need for quick and tailored image generation without the hassle of traditional graphic design processes.

Input Requirements

The input for this action requires a structured JSON object, with the following key elements:

  • prompt: A descriptive text that defines the content and style of the image.
  • Additional optional parameters include:
    • mask: URI of an image mask for inpainting mode.
    • seed: An integer seed for random number generation.
    • image: URI of an input image for modification.
    • width and height: Specify dimensions within the allowed range.
    • imageFormat: Choose the output format (e.g., jpg, png).
    • imageQuality: Set the quality level for the output image.
    • inferenceModel: Select between models for optimized results.
    • numberOfOutputs: Define how many images to generate.

Expected Output

The output will be a URI linking to the generated image, allowing immediate access to the visual content created based on your specifications.

Use Cases for this Specific Action

  • Marketing Campaigns: Quickly create visuals that resonate with your target audience, enhancing engagement.
  • Content Creation: Generate unique images for articles, blogs, or social media posts that stand out and capture attention.
  • Personalization: Tailor images to specific themes or events, providing customized graphics for users or clients.
  • Prototyping: Use generated images in app or website prototypes to visualize concepts and ideas effectively.
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 = "9d1e8d52-2918-46ab-96b2-ca1781a3ac20" # Action ID for: Generate Custom Images

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "prompt": "krameran   A six-month-old baby in a home hallway with an open door behind him, wild spiky baby hair, slightly loose pajamas, holding a small toy in the air with a surprised expression, as if he just burst into the room",
  "imageFormat": "jpg",
  "imageQuality": 80,
  "mainLoraScale": 1,
  "enableFastMode": false,
  "inferenceModel": "dev",
  "inferenceSteps": 28,
  "numberOfOutputs": 1,
  "promptIntensity": 0.8,
  "imageAspectRatio": "16:9",
  "outputMegapixels": "1",
  "additionalLoraScale": 1,
  "diffusionGuidanceScale": 3
}

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

Krameran's "Generate Custom Images" action opens up a world of possibilities for developers looking to enhance their applications with dynamic visuals. By enabling quick and customizable image generation, it streamlines the content creation process, allowing for greater creativity and efficiency. Whether for marketing, personal projects, or professional purposes, integrating this action can significantly elevate the quality and appeal of your visual content. Explore the potential of Krameran today and start creating stunning images tailored to your unique requirements.