Transform Your Images with Blur Effects Using Cognitive Actions

23 Apr 2025
Transform Your Images with Blur Effects Using Cognitive Actions

In the world of image processing, applying effects can dramatically enhance the visual appeal of photographs or graphics. The ahm3texe/blur API provides developers with a powerful tool to apply blur effects to images effortlessly. This blog post will guide you through the capabilities of the Cognitive Action called Apply Image Blur Effect, detailing how to integrate it into your applications for stunning results.

Prerequisites

Before diving into the implementation, ensure you have the following prerequisites:

  • An API key for the Cognitive Actions platform, which will be used for authentication.
  • A direct URL to an image that you want to process. The image must be accessible publicly to ensure successful processing.

Authentication is typically handled via HTTP headers, where you'll pass your API key to authorize your requests.

Cognitive Actions Overview

Apply Image Blur Effect

The Apply Image Blur Effect action softens an image by applying a specified level of blur, effectively reducing detail and creating a smoother appearance. This action is part of the image-processing category and is perfect for developers looking to enhance their images with minimal effort.

Input

The input for this action requires a JSON object with the following schema:

{
  "image": "string (uri)",
  "blur": "number (optional, default: 5)"
}
  • image (required): A URI pointing to the input image that you wish to process. It must be accessible via a direct URL.
  • blur (optional): A number representing the radius of the blur effect to apply. The default value is 5, but you can specify a different value for a more pronounced effect.

Example Input:

{
  "blur": 10,
  "image": "https://replicate.delivery/pbxt/MAT1S5CrMehUJpkarzilKmk9v4hlcSnq1BRx3luRtdIv2Wrv/WhatsApp%20Image%202024-12-12%20at%2023.13.44.jpeg"
}

Output

Upon successful execution, the action will return a URI link to the processed image with the blur effect applied. Here is an example of the output:

"https://assets.cognitiveactions.com/invocations/de03d115-5409-4905-b944-5718fb479e11/a778ccf8-00b1-46bf-8aac-cafab58fbd72.png"

This output is a direct link to the newly created image.

Conceptual Usage Example (Python)

Here’s a conceptual Python code snippet demonstrating how to call the Apply Image Blur Effect action:

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 = "d27b8147-208f-48c2-b508-d2d498118fd6"  # Action ID for Apply Image Blur Effect

# Construct the input payload based on the action's requirements
payload = {
    "blur": 10,
    "image": "https://replicate.delivery/pbxt/MAT1S5CrMehUJpkarzilKmk9v4hlcSnq1BRx3luRtdIv2Wrv/WhatsApp%20Image%202024-12-12%20at%2023.13.44.jpeg"
}

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 snippet:

  • Replace the placeholders with your actual API key and endpoint.
  • The action ID is set to the unique identifier of the Apply Image Blur Effect action.
  • The payload is constructed based on the example input, ensuring the correct structure for the request.

Conclusion

Integrating the Apply Image Blur Effect from the ahm3texe/blur Cognitive Actions into your applications can enhance the visual quality of images with ease. By following the steps outlined in this guide, you can quickly implement this feature and experiment with different blur levels to achieve the desired effect.

Explore more use cases, such as applying different visual effects or automating image processing tasks, to further enrich your applications!