Transform Your Images with Photomaker's Stylish Generation Actions

27 Apr 2025
Transform Your Images with Photomaker's Stylish Generation Actions

In the world of digital content creation, standing out visually can be the key to engagement and impact. Photomaker provides powerful Cognitive Actions designed to help developers easily create stunning styled images from existing photos. With a variety of style templates and customization options, developers can enhance their applications by adding artistic flair to their images, making them more appealing and shareable.

Imagine being able to transform a standard photo into a vibrant, comic book-style image or a dreamy cinematic scene. Photomaker's image generation capabilities simplify this process, allowing developers to focus on creativity rather than complex image manipulation tasks. Whether you are building a social media platform, a graphic design tool, or an art application, these actions can elevate your user experience and give your projects a unique touch.

Prerequisites

To get started with Photomaker, you'll need an API key for the Cognitive Actions service and a basic understanding of making API calls.

Generate Styled Image

The Generate Styled Image action allows you to create visually captivating images by applying various artistic styles to an input image. By leveraging style templates such as Cinematic, Neonpunk, and Comic Book, this action helps solve the problem of bland imagery, enabling developers to create standout visuals effortlessly.

Input Requirements

  • primaryInputImage: A URI pointing to the primary image you want to style (required).
  • prompt: A text prompt that describes the desired image with a trigger word 'img' (e.g., "A photo of a person img").
  • styleName: Specifies the style template to apply (e.g., "Neonpunk").
  • guidanceScale: Adjusts the level of adherence to the prompt (1-10).
  • numberOfSteps: Defines how detailed the image generation process should be (1-100).
  • negativePrompt: Lists elements to avoid in the generated image (e.g., "nsfw, lowres").
  • numberOfOutputs: Indicates how many styled images to generate (1-4).
  • styleStrengthPercentage: Sets the intensity of the style effect (15%-50%).

Expected Output

The action returns one or more styled images as URIs, allowing easy integration into your applications. For example, you might receive links to images like:

  • https://assets.cognitiveactions.com/invocations/3626ddeb-6328-4cda-8a8a-d072d170ebdc/2f1d841b-c3ec-47cc-9eb7-abcc5643f5e9.png
  • https://assets.cognitiveactions.com/invocations/3626ddeb-6328-4cda-8a8a-d072d170ebdc/6a7c5c35-3e0c-4636-96ed-196f8dce2274.png

Use Cases for this Action

  • Social Media Applications: Enhance user-generated content by allowing users to style their photos before sharing.
  • Graphic Design Tools: Provide designers with quick styling options for mockups and presentations.
  • Art Applications: Enable artists to explore different styles and inspirations by transforming their images into various artistic forms.

```python
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 = "5a329e27-5454-4398-b640-c72a2583d3d6" # Action ID for: Generate Styled Image

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "prompt": "A photo of a man img",
  "styleName": "Neonpunk",
  "guidanceScale": 5,
  "numberOfSteps": 50,
  "negativePrompt": "nsfw, lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry",
  "numberOfOutputs": 2,
  "primaryInputImage": "https://replicate.delivery/pbxt/L37IX7NnujQfuIgDUCm6tI1Rp5RCHn7IXtNVr6katCV2Gxjv/hazem.png",
  "styleStrengthPercentage": 30
}

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
Photomaker's styled image generation capabilities open up a world of creative possibilities for developers. By integrating these Cognitive Actions, you can provide users with the tools to transform ordinary images into extraordinary visuals, enhancing engagement and interaction within your applications. Start experimenting with these actions today and elevate the visual appeal of your projects!