version 1.6
歡迎使用 MDAI設計師 API!此 API 可以讓您根據自訂的文字生成高品質的圖片或圖片風格變換。
Welcome to the MDAI Graphic Designer API! This API allows you to generate high-quality images with customized text prompts or image style change.
server not running now ***
如非特別註明,以下功能有幾點需注意:
圖片格式需為JPG或PNG,建議輸入長寬比為1:1的圖片。
API會先將文字翻譯成英文再執行圖像轉換。
返回的圖片將為PNG。
Unless otherwise specified, there are a few points to note for the following functions:
The image format needs to be JPG or PNG,It is recommended to input images with a 1:1 aspect ratio.
The API will first translate the input into English before performing the image transformation.
The returned image will be in PNG format.
此 API 支援中文文字輸入。如果您的提示包含中文字元,API 會在生成圖片前自動將其翻譯成英文。然而,自動翻譯可能不準確,並導致生成的圖片與期望不相符。
This API supports Chinese text input. If your prompt contains Chinese characters, the API will automatically translate them into English before generating the image. However, automatic translation may be inaccurate and can result in the generated image not matching your expectations.
"/text2image/" 文字描述生成圖像生成並返回基於提供的提示的圖片。
Generates and returns an image based on the provided prompt.
"/getimage/" 文字描述生成圖像,直接返回可下載的附件基於提示詞句的圖片生成圖片,將以可下載的附件返回給用戶。
Generate a picture based on the picture of the prompt words, and return it to the user as a downloadable attachment.
"/image2image/" 圖像轉變圖像,風格轉化需要一個提示詞句和一張圖片作為輸入。
It expects a prompt string and an image file as input.The prompt string is used to guide the image translation prompt or original prompt is then passed to the api,which performs the actual image translation.
"/3style/" 快速生成3種風格需要一個預設詞和一張圖片作為輸入。可選詞:"oil painting","ink painting","quick sketch"。
A preset word and a picture are required as input. Optional words: "oil painting", "ink painting", "quick sketch".
"/imagepaint/" 變換指定目標與圖像轉圖像類似,但它可以輸入一個遮罩層來控制您需要更改的圖像區域。
Same like image to image,but it can input a mask layer to control your image where need to change.
"/upscaler/" AI放大圖像 x4用 AI 放大圖像4倍並保留細節。
注意:返回圖片將會是JPG格式
Uses AI to enlarge images by 4x and preserve details.
Important Note: The returned image will be in JPG format ***
"/text2image/{prompt}"向 http://2dgpn.ai.marveldigital.com/text2image/{prompt} 發送 GET 請求,其中包含您要生成的prompts。API將以 base64 編碼的PNG圖像回應。Prompt: str
Send a GET request to http://2dgpn.ai.marveldigital.com/text2image/{prompt} with the prompts you want to generate an image from. The response will be the generated PNG image encoded in base64.
"/getimage/{prompt}"向 http://2dgpn.ai.marveldigital.com/getimage/{prompt} 發送 GET 請求,其中包含您要生成圖片的prompt。API將返回PNG格式的圖片附件作為回應。Prompt: str
Send a GET request to http://2dgpn.ai.marveldigital.com/getimage/{prompt} with the prompts you want to generate an image from. The response will be the generated image as an attachment that can be downloaded by the user.
"/image2image/{prompt}"向 http://2dgpn.ai.marveldigital.com/image2image/ 發送 POST 請求,其中包含您要生成PNG圖片的prompt和您的輸入圖片 "img"。API將以 base64 編碼的PNG圖像應回應。Prompt: str
img: your image
Send a POST request to http://2dgpn.ai.marveldigital.com/image2image/ with the prompts and your input image "img" you want to generate an image from. The response will be the generated PNG image encoded in base64.
"/3style/{prompt}"向 http://2dgpn.ai.marveldigital.com/3style/ 發送 POST 請求,其中包含您的輸入圖片 "img"。API將以 base64 編碼的PNG圖像應回應。Prompt: str
img: your image
Send a POST request to http://2dgpn.ai.marveldigital.com/3style/ with the prompts and your input image "img" you want to generate an image from. The response will be the generated PNG image encoded in base64.
"/imagepaint/{prompt}"Prompt: str
img: your image
Maskimg: your image
向 http://2dgpn.ai.marveldigital.com/image2image/ 發送 POST 請求,其中包含prompt,輸入圖片 "img" 和 遮罩圖片 "Maskimg",將以 base64 編碼的PNG圖像回應。
Send a POST request to http://2dgpn.ai.marveldigital.com/image2image/ with the prompt , input image "img" and mask image "Maskimg" ,it will generate an PNG image encoded in base64.
"/upscalerX4/"img: your image
向 http://2dgpn.ai.marveldigital.com/upscalerX4/ 發送 POST 請求,其中包含輸入圖片 "img",將以返回放大了4倍的 base64 編碼JPG圖像。
Send a POST request to http://2dgpn.ai.marveldigital.com/upscalerX4/ with input image "img",it will up scale an JPG image encoded in base64 by 4. ***
Fast connection test:http://2dgpn.ai.marveldigital.com/test
Success log: {"message":"server Connected!"} 以下是一些python使用API的例子以供參考
Here are some examples of python using the API for reference
import requests
from PIL import Image
import io
import base64
# Supports Chinese text prompts可以輸入中文字
prompt = "一名太空人在森林中跑步,科幻,水彩風格"
response = requests.get(f"http://2dgpn.ai.marveldigital.com/text2image/{prompt}")
img = Image.open(io.BytesIO(base64.b64decode(response.content)))
img.show()
import requests
prompt = "An astronaut runs in the forest, sci-fi, watercolor style"
response = requests.get(f"http://2dgpn.ai.marveldigital.com/getimage/{prompt}")
with open('generated_image.png', 'wb') as f:
f.write(response.content)
import requests
from io import BytesIO
from PIL import Image
import base64
API_image2iamge = "http://2dgpn.ai.marveldigital.com/image2image/"
img_path = "./harbour-thumbnail.jpg"
prompt = "by Makoto Shinkai"
with open(img_path,"rb") as f:
img_data = f.read()
response = requests.post(
API_image2iamge+"?prompt="+prompt,
files = {"img": img_data})
output_img = Image.open(BytesIO(base64.b64decode(response.content)))
output_img.show()
import requests
from io import BytesIO
from PIL import Image
import base64
from datetime import datetime
API_3style = "http://2dgpn.ai.marveldigital.com/3style/"
img_path = "1.png"
data="oil painting" ##'oil painting' or 'ink painting' or 'quick sketch'
with open(img_path,"rb") as f:
img_data = f.read()
response = requests.post(
API_3style,
files = {"img": img_data},
data = {"choice": data }
)
output_img_data = base64.b64decode(response.content)
output_img = Image.open(BytesIO(output_img_data))
output_img.show()
import requests
from io import BytesIO
from PIL import Image
import base64
API_inpaint = "http://2dgpn.ai.marveldigital.com/imagepaint/"
img_path = "./harbour-thumbnail.jpg"
mask_path = "./harbour-thumbnail.jpg"
prompt = "Makoto Shinkai style"
with open(img_path,"rb") as f:
img_data = f.read()
with open(mask_path,"rb") as f:
mask_data = f.read()
response = requests.post(
API_inpaint + "?prompt=" + prompt,
files = {"img": ("input_image.jpg",img_data),"Maskimg":("mask_layer_image.jpg", mask_data)})
if response.ok:
output_img = Image.open(BytesIO(base64.b64decode(response.content)))
output_img.show()
print("Inpainting comleted successfully!")
else:
print("Error:", response.status_code, response.reason)
import requests
from PIL import Image
import io
url = "http://2dgpn.ai.marveldigital.com/upscalerX4/"
image_path = "your_input_image.png"
# Open the image and convert it to bytes
image = Image.open(image_path)
img_byte_arr = io.BytesIO()
image.save(img_byte_arr, format='PNG')
img_bytes = img_byte_arr.getvalue()
# Send the POST request with the image data
response = requests.post(url, files={"img": img_bytes})
# Get the base64 encoded response image
response_image_base64 = response.text
# Decode the base64 encoded image and display it
response_image_bytes = base64.b64decode(response_image_base64)
response_image = Image.open(io.BytesIO(response_image_bytes))
response_image.show()
10/05/2023