Transform and Stylize Images Effortlessly with the Image Editing API

The Image Editing And Prediction API offers developers an innovative way to enhance and transform images using advanced AI capabilities. With this API, you can effortlessly stylize images, optimize processing speed, and tailor output quality to meet your specific needs. Whether you’re looking to create stunning visual content for marketing, enhance user-generated images, or automate graphic design tasks, this API simplifies the image editing process, allowing you to focus on creativity rather than technical details.
Imagine a scenario where you need to create personalized marketing materials that stand out. With this API, you can transform standard images into eye-catching visuals in just a few clicks. Additionally, the ability to adjust processing speed and quality ensures that you can balance performance with the desired output, making it a versatile tool for various applications.
Transform Image with HiDream-E1
The Transform Image with HiDream-E1 action allows you to utilize the powerful HiDream-E1 model, enhanced by the Pruna optimization engine, to transform and stylize images effectively. This action is particularly useful for developers looking to create visually appealing content while saving time and resources.
Input Requirements
To use this action, you will need to provide a composite request, including:
- Image: The URI of the input image you want to edit.
- Prompt: A descriptive text outlining the desired transformation or style.
- Random Seed: An integer for consistent results, where -1 indicates a random seed.
- Result Format: The desired output format (options include PNG, JPG, or WEBP).
- Result Quality: A quality level for the output image, applicable for JPG and WEBP formats (ranging from 1 to 100).
- Processing Speed Mode: Choose between different speed optimization levels for processing.
- Visual Guidance Scale: A numeric scale guiding the visual aspects of the transformation.
- Control Guidance Scale: A scale influencing the guidance strength for the transformation process.
- Number of Inference Steps: Total steps for the inference process.
Example Input:
{
"image": "https://raw.githubusercontent.com/HiDream-ai/HiDream-E1/refs/heads/main/assets/test_1.png",
"prompt": "Convert the image into a 3D animated style.",
"randomSeed": -1,
"resultFormat": "webp",
"resultQuality": 80,
"processingSpeedMode": "Juiced 🔥 (more speed)",
"visualGuidanceScale": 2,
"controlGuidanceScale": 3.5,
"numberOfInferenceSteps": 28
}
Expected Output
The output will be a transformed image based on the specified prompt and parameters, delivered in the chosen format. For instance, if the prompt involves creating a 3D animated style, the output will reflect that transformation.
Example Output:
https://assets.cognitiveactions.com/invocations/56019098-36f2-4d6f-bbc4-fe51d4f221d7/4c2db58a-131d-4b43-b57d-50517fbcfe9b.webp
Use Cases for this Action
- Marketing and Advertising: Quickly generate unique visuals for campaigns that capture attention and engage audiences.
- Content Creation: Automate the enhancement of user-generated images for social media or blogs, ensuring professional quality without manual editing.
- Graphic Design Automation: Streamline the design process for applications that require multiple image transformations, saving designers time and effort.
```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 = "7d3d8e99-5f52-4d84-86d0-44259e8eaa69" # Action ID for: Transform Image with HiDream-E1
# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
"image": "https://raw.githubusercontent.com/HiDream-ai/HiDream-E1/refs/heads/main/assets/test_1.png",
"prompt": "Convert the image into a 3D animated style.",
"randomSeed": -1,
"resultFormat": "webp",
"resultQuality": 80,
"processingSpeedMode": "Juiced 🔥 (more speed)",
"visualGuidanceScale": 2,
"controlGuidanceScale": 3.5,
"numberOfInferenceSteps": 28
}
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 Image Editing And Prediction API empowers developers to transform images effortlessly while offering flexibility in processing speed and output quality. By leveraging the HiDream-E1 model, you can create visually stunning content that meets your specific needs and enhances user engagement. As you explore this API, consider how it can fit into your projects, whether for marketing, content creation, or graphic design automation. Start integrating today and elevate your image editing capabilities!