🎨 Image-to-Image Generation (img2img)

Image-to-image (img2img) generation is a powerful feature that allows you to transform an existing image based on a new prompt or specific parameters. Instead of generating an image from scratch, you provide an input image, and the AI uses it as a foundation to create a new visual. This is incredibly useful for style transfer, image variations, or modifying existing assets while maintaining their core composition.

How it Works:

With img2img, the AI takes both a textual prompt and an input image. The strength parameter plays a crucial role here, determining how much the generated image deviates from the original input image. A higher strength value means the AI will take more creative liberties, while a lower value will result in an output closer to the original.

Example: Transforming a Landscape

Let's say you have an image of a serene forest and you want to transform it into a mystical, glowing forest. You would provide the original forest image and a prompt like "a mystical forest, glowing flora, ethereal light."

cURL

curl -X POST \
  -u "YOUR_API_KEY:YOUR_API_SECRET" \
  -H "Content-Type: application/json" \
  -d 
'{
    "prompt": "a mystical forest, glowing flora, ethereal light",
    "imageUrl": "https://example.com/your-forest-image.jpg", # URL of your input image
		# you can also use image, using an assetId
    "strength": 0.75,
    "numSamples": 1,
    "guidance": 3.5,
    "numInferenceSteps": 28,
    "modelId": "flux.1-dev" 
}' \
  https://api.scenario.com/v1/generate/img2img

Python

import requests

api_key = "YOUR_API_KEY"
api_secret = "YOUR_API_SECRET"

url = "https://api.scenario.com/v1/generate/img2img"
headers = {"Content-Type": "application/json"}

payload = {
    "prompt": "a mystical forest, glowing flora, ethereal light",
    "imageUrl": "https://example.com/your-forest-image.jpg", # URL of your input image
  	# you can also use image, using an assetId
    "strength": 0.75,
    "numSamples": 1,
    "guidance": 3.5,
    "numInferenceSteps": 28,
    "modelId": "flux.1-dev"
}

response = requests.post(url, headers=headers, json=payload, auth=(api_key, api_secret))

## you need to handle the evolution of the job
if response.status_code == 200:
    data = response.json()
    print("Image generation successful!")
    print("Generated Image ID:", data["metadata"]["assetIds"][0])
else:
    print(f"Error: {response.status_code} - {response.text}")