DEV Community

Cover image for Turn Any Photo into Ghibli Art for Free with Python (3 Lines)
AI Engine
AI Engine

Posted on • Originally published at ai-engine.net

Turn Any Photo into Ghibli Art for Free with Python (3 Lines)

Studio Ghibli's art style has taken over social media. The hand-drawn look, the soft colors, the dreamy landscapes. Everyone wants their photos to look like a frame from Spirited Away.

Most tutorials tell you to install PyTorch, download a 2GB model, and fight with CUDA drivers. Not necessary. With an API, you can do it in 3 lines of Python, for free.

The Result

Before and after: landscape photo transformed into Ghibli style

The Code

import requests

response = requests.post(
    "https://phototoanime1.p.rapidapi.com/ghibli",
    headers={"x-rapidapi-key": "YOUR_API_KEY", "x-rapidapi-host": "phototoanime1.p.rapidapi.com"},
    files={"image": open("my_photo.jpg", "rb")},
)
print(response.json()["image_url"])
Enter fullscreen mode Exit fullscreen mode

The response:

{
  "image_url": "https://images.ai-engine.net/photo-to-anime-ai/abc123.jpg",
  "width": 640,
  "height": 960,
  "size_bytes": 126722
}
Enter fullscreen mode Exit fullscreen mode

Open the URL and you have your Ghibli art. No PyTorch, no CUDA, no model file.

What You Need

  • Python with requests (pip install requests)
  • A free API key from RapidAPI
  • A photo (JPEG, PNG, or WebP, up to 10MB)

The free tier gives you 50 transformations per month. No credit card.

Download the Result

image_data = requests.get(result["image_url"]).content
with open("ghibli_output.jpg", "wb") as f:
    f.write(image_data)
Enter fullscreen mode Exit fullscreen mode

You Can Also Use a URL

response = requests.post(
    "https://phototoanime1.p.rapidapi.com/ghibli",
    headers={**HEADERS, "Content-Type": "application/x-www-form-urlencoded"},
    data={"url": "https://example.com/my_photo.jpg"},
)
Enter fullscreen mode Exit fullscreen mode

API vs Local Model

Local Model Ghibli API
Setup PyTorch + 2GB model pip install requests
GPU Required Not needed
Code 20-30 lines 3 lines
Cost Free (need GPU hardware) Free (50/month)
Quality Depends on model Face-aware with background blending

7 Other Styles

The same API also offers 7 cartoon styles via /cartoonize: anime, 3d, handdrawn, sketch, artstyle, design, illustration.

response = requests.post(
    "https://phototoanime1.p.rapidapi.com/cartoonize",
    headers=HEADERS,
    files={"image": open("photo.jpg", "rb")},
    data={"style": "anime"},
)
Enter fullscreen mode Exit fullscreen mode

Tips

  • Use clear, well-lit portraits for best results
  • Front-facing photos work best
  • The API handles up to 10MB images

👉 Read the full tutorial with more examples

Top comments (0)