├── .gitignore ├── docs ├── koala.jpeg ├── examples │ ├── winslet_emoji.jpg │ ├── winslet_toonify.jpg │ ├── winslet_zombie.jpg │ ├── will_smith_emoji.jpg │ ├── will_smith_toonify.jpg │ ├── will_smith_zombie.jpg │ ├── winslet_caricature.jpg │ ├── winslet_halloween.jpg │ ├── winslet_toonifyhd.jpg │ ├── will_smith_halloween.jpg │ ├── will_smith_toonifyhd.jpg │ ├── winslet_toonifyplus.jpg │ ├── will_smith_caricature.jpg │ └── will_smith_toonifyplus.jpg ├── version-change-log.md ├── index.md ├── tips-and-considerations.md ├── models.md ├── more-options.md └── getting-started.md └── mkdocs.yml /.gitignore: -------------------------------------------------------------------------------- 1 | venv/ -------------------------------------------------------------------------------- /docs/koala.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justinpinkney/toonify-api-docs/main/docs/koala.jpeg -------------------------------------------------------------------------------- /docs/examples/winslet_emoji.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justinpinkney/toonify-api-docs/main/docs/examples/winslet_emoji.jpg -------------------------------------------------------------------------------- /docs/examples/winslet_toonify.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justinpinkney/toonify-api-docs/main/docs/examples/winslet_toonify.jpg -------------------------------------------------------------------------------- /docs/examples/winslet_zombie.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justinpinkney/toonify-api-docs/main/docs/examples/winslet_zombie.jpg -------------------------------------------------------------------------------- /docs/examples/will_smith_emoji.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justinpinkney/toonify-api-docs/main/docs/examples/will_smith_emoji.jpg -------------------------------------------------------------------------------- /docs/examples/will_smith_toonify.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justinpinkney/toonify-api-docs/main/docs/examples/will_smith_toonify.jpg -------------------------------------------------------------------------------- /docs/examples/will_smith_zombie.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justinpinkney/toonify-api-docs/main/docs/examples/will_smith_zombie.jpg -------------------------------------------------------------------------------- /docs/examples/winslet_caricature.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justinpinkney/toonify-api-docs/main/docs/examples/winslet_caricature.jpg -------------------------------------------------------------------------------- /docs/examples/winslet_halloween.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justinpinkney/toonify-api-docs/main/docs/examples/winslet_halloween.jpg -------------------------------------------------------------------------------- /docs/examples/winslet_toonifyhd.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justinpinkney/toonify-api-docs/main/docs/examples/winslet_toonifyhd.jpg -------------------------------------------------------------------------------- /docs/examples/will_smith_halloween.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justinpinkney/toonify-api-docs/main/docs/examples/will_smith_halloween.jpg -------------------------------------------------------------------------------- /docs/examples/will_smith_toonifyhd.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justinpinkney/toonify-api-docs/main/docs/examples/will_smith_toonifyhd.jpg -------------------------------------------------------------------------------- /docs/examples/winslet_toonifyplus.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justinpinkney/toonify-api-docs/main/docs/examples/winslet_toonifyplus.jpg -------------------------------------------------------------------------------- /docs/examples/will_smith_caricature.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justinpinkney/toonify-api-docs/main/docs/examples/will_smith_caricature.jpg -------------------------------------------------------------------------------- /docs/examples/will_smith_toonifyplus.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justinpinkney/toonify-api-docs/main/docs/examples/will_smith_toonifyplus.jpg -------------------------------------------------------------------------------- /docs/version-change-log.md: -------------------------------------------------------------------------------- 1 | ## v0.1.0 - 27th October 2020 2 | 3 | - Added new [model](models) endpoints 4 | 5 | ## v0.0.1 - 13th October 2020 6 | 7 | - Added `crop_edges` option 8 | - Added `proceed_without_face` option -------------------------------------------------------------------------------- /mkdocs.yml: -------------------------------------------------------------------------------- 1 | site_name: Toonify API Documentation 2 | theme: 3 | name: material 4 | markdown_extensions: 5 | - pymdownx.highlight 6 | - pymdownx.superfences 7 | - pymdownx.inlinehilite 8 | - admonition -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | # Toonify API 2 | 3 | _Welcome to the documentation for the Toonify API!_ 4 | 5 | We provide API access to the Toonification model made famous by [Toonify Yourself](https://toonify.photos) and [other models too.](models) 6 | 7 | The API is accessible through RapidAPI (who take care of all the authentication and billing for us). Please [sign up for an API key](https://rapidapi.com/toonify-toonify-default/api/toonify/details) first. 8 | 9 | __If you have an API key then take a look at our [Getting Started tutorial](getting-started).__ 10 | 11 | __Or if you just want to start making request check out our [interactive endpoint explorer](https://toonify.photos/api/interactive) to start getting results staight away.__ 12 | 13 | !!! warning 14 | The RapidAPI interactive endpoint explorer does not properly send requests as multipart/form-data. It won't work, so please don't use it. 15 | 16 | If you've got any feedback please create an [issue on GitHub](https://github.com/justinpinkney/toonify-api-docs/issues), or reach out to me [on Twitter](twitter.com/buntworthy). 17 | 18 | ![](https://assets.justinpinkney.com/toonify/images/social.jpg) 19 | -------------------------------------------------------------------------------- /docs/tips-and-considerations.md: -------------------------------------------------------------------------------- 1 | ## Please note 2 | 3 | - __The current model costs 2 credits per use. We expect to introduce other models for both more and fewer credits in future.__ 4 | - This works out around 45 cents per thousand uses for one of the prepaid bundles. If you're interested in different pricing bundles then please contact us. 5 | - Inference time is around 7 seconds. I could to much to improve this is there is sufficient demand and usage. 6 | - We expect to release other models, for different transformations and also different resolutions. If you're interested in something please let us know! 7 | - If you want to see examples of the current Toonify model being used look at https://toonify.justinpinkney.com 8 | - The RapidAPI endpoint interface doesn't appear to send mulipart/form data properly, so doesn't work. Please see our code examples for reference. 9 | 10 | ## How to get good results 11 | 12 | - Make sure the original image is fairly high quality (e.g. face is around 512x512 pixels) 13 | - Faces in the image which are below around 128x128 pixels are unlikely to be found 14 | - Straight on faces work best, side on faces aren't likely to be found. -------------------------------------------------------------------------------- /docs/models.md: -------------------------------------------------------------------------------- 1 | We currently provide API access to 4 different models. __Note the different models consume different numbers of Credits for each API call__ 2 | 3 | _NEW !_ 4 | ## Toonify HD 5 | 6 | - __Credits per call = 100__ 7 | - Endpoint: `v0/toonifyhd` 8 | - Produces a toonify style image at 1024x1024 resolution 9 | - Only available on the MEGA subscription 10 | 11 | ![](examples/will_smith_toonifyhd.jpg) 12 | ![](examples/winslet_toonifyhd.jpg) 13 | 14 | ## Caricature 15 | 16 | - __Credits per call = 4__ 17 | - Endpoint: `v0/caricature` 18 | - Produces a caricature style image 19 | 20 | ![](examples/will_smith_caricature.jpg) 21 | ![](examples/winslet_caricature.jpg) 22 | 23 | ## Toonify 24 | 25 | - __Credits per call = 2__ 26 | - Endpoint: `v0/toonify` 27 | - The original Toonify model 28 | 29 | ![](examples/will_smith_toonify.jpg) 30 | ![](examples/winslet_toonify.jpg) 31 | 32 | ## Emojify 33 | 34 | - __Credits per call = 4__ 35 | - Endpoint: `v0/emojify` 36 | - Produces an emoji style image 37 | 38 | ![](examples/will_smith_emoji.jpg) 39 | ![](examples/winslet_emoji.jpg) 40 | 41 | 42 | ## Zombify 43 | 44 | - __Credits per call = 4__ 45 | - Endpoint: `v0/zombify` 46 | - Zombie model from https://makemeazombie.com/ 47 | 48 | ![](examples/will_smith_zombie.jpg) 49 | ![](examples/winslet_zombie.jpg) 50 | 51 | 52 | ## Toonifyplus 53 | 54 | - __Credits per call = 4__ 55 | - Endpoint: `v0/toonifyplus` 56 | - Toon style image more faithful to original features and more noise resistant 57 | 58 | ![](examples/will_smith_toonifyplus.jpg) 59 | ![](examples/winslet_toonifyplus.jpg) 60 | 61 | 62 | ## Halloweenify 63 | 64 | - __Credits per call = 4__ 65 | - Endpoint: `v0/halloweenify` 66 | - Zombie/horror like appearance 67 | 68 | ![](examples/will_smith_halloween.jpg) 69 | ![](examples/winslet_halloween.jpg) 70 | -------------------------------------------------------------------------------- /docs/more-options.md: -------------------------------------------------------------------------------- 1 | In the previous example you saw one query parameter that you can pass `return_aligned` to receive the original cropped face or not. There are a few other parameters that the API currently exposes: 2 | 3 | - `face_index` (default: 0) 4 | - `crop_edges` (default: 0) 5 | - `proceed_without_face` (default: False) 6 | 7 | ## Indexing faces 8 | 9 | One of the json response fields is `num_faces` this tells you how many faces were detected in the original image. If there are multiple faces in the image then you can toonify all of them by passing an extra query parameter of `face_index`. This zero based index controls which detected face will be sent for toonifcation. 10 | 11 | ```python 12 | import requests 13 | 14 | url = "https://toonify.p.rapidapi.com/v0/toonify" 15 | query = { 16 | "face_index": 1, # Process the second face in the image 17 | } 18 | headers = { 19 | "x-rapidapi-host": "toonify.p.rapidapi.com", 20 | "x-rapidapi-key": "KEY_HERE", 21 | "accept": "application/json", 22 | } 23 | files = {"image": open("imagefile.jpg", "rb")} 24 | 25 | response = requests.request("POST", url, files=files, headers=headers, params=query) 26 | 27 | print(response.json()) 28 | ``` 29 | 30 | ## Cropping edges 31 | 32 | The original model processes images at 512x512 pixels. Sometimes these edges are quite low quality, especially if the original image is a tight crop. You can remove these and get a (slightly) faster response time by setting the `crop_edges` parameter to be greater than 0. Generally 16 is a good value, but multiples of 8 are recommended. 33 | 34 | ## Behaviour when no face is found 35 | 36 | The `proceed_without_face` parameter controls the behaviour if no face is found. By default if no face is found the API returns an error. If you set `proceed_without_face` to be True, we will simply resize and process the full original image as is, the quality in this case is likely to not be good. 37 | 38 | ![](koala.jpeg) 39 | 40 | ## Example with all the options 41 | 42 | ```python 43 | import requests 44 | 45 | url = "https://toonify.p.rapidapi.com/v0/toonify" 46 | headers = { 47 | "x-rapidapi-host": "toonify.p.rapidapi.com", 48 | "x-rapidapi-key": "KEY_HERE", 49 | "accept": "application/json", 50 | } 51 | query = { 52 | "face_index": 1, # Process the second face in the image 53 | "crop_edges": 16, # crop a 16 pixel border from the image 54 | "proceed_without_face": True, # Process even when no face is found 55 | } 56 | files = {"image": open("imagefile.jpg", "rb")} 57 | 58 | response = requests.request("POST", url, files=files, headers=headers, params=query) 59 | 60 | print(response.json()) 61 | ``` 62 | 63 | __Next see [tips and considerations](tips and considerations) in using the API.__ -------------------------------------------------------------------------------- /docs/getting-started.md: -------------------------------------------------------------------------------- 1 | !!! warning 2 | There seems to be an issue with the RapidAPI interactive endpoint explorer not properly sending requests as multipart/form-data. Make sure you use this guide as your reference for testing the API as the code snippets generated by RapidAPI don't work. Instead, please visit our own [interactive endpoint page](https://toonify.photos/api/interactive). 3 | 4 | !!! info 5 | All the examples below use the `v0/toonify` endpoint for the original Toonify model. We have [other models](../models) available at different endpoints. The expected parameters etc. are all the identical between the models, so the examples should work simply by changing the url. 6 | 7 | ## First steps 8 | 9 | The following example uses the Python library Requests to send an image file for toonification. If the `Accept` header is `application/json` the response will be json, with images base64 encoded. 10 | 11 | ```python 12 | import requests 13 | 14 | url = "https://toonify.p.rapidapi.com/v0/toonify" 15 | headers = { 16 | "x-rapidapi-host": "toonify.p.rapidapi.com", 17 | "x-rapidapi-key": "KEY_HERE", 18 | "accept": "application/json", 19 | } 20 | files = {"image": open("imagefile.jpg", "rb")} 21 | 22 | response = requests.request("POST", url, files=files, headers=headers) 23 | 24 | print(response.json()) 25 | ``` 26 | 27 | will return a json response like this: 28 | 29 | ```json 30 | { 31 | "num_faces": 1, 32 | "b64_encoded_output": "BASE64_IMAGE_HERE", 33 | "b64_encoded_aligned": "" 34 | } 35 | ``` 36 | 37 | !!! note 38 | When returning a json response all images are base64 encoded and returned as a string. Here's an example of how to read one of these into a PIL Image in Python: 39 | 40 | ```python 41 | import base64 42 | from io import BytesIO 43 | from PIL import Image 44 | 45 | b64_encoded_output = "BASE64_IMAGE_HERE" 46 | file_like = BytesIO(base64.b64decode(b64_encoded_output)) 47 | image = Image.open(file_like) 48 | 49 | image.show() 50 | ``` 51 | 52 | ## Returning an image 53 | 54 | If you want an image directly returned then set the `Accept` header to `image/jpeg`. Here is an example using curl for variety. 55 | 56 | ```bash 57 | curl -X POST "https://toonify.p.rapidapi.com/v0/toonify" -H "accept: image/jpeg" -H "Content-Type: multipart/form-data" -H "x-rapidapi-host: toonify.p.rapidapi.com" -H "x-rapidapi-key: KEY_HERE" -F "image=@test.jpg;type=image/jpeg" 58 | ``` 59 | 60 | 61 | ## Returning aligned image 62 | 63 | If you want to return the cropped and aligned face as well as the toonified result you can pass a query parameter of `return_aligned=True`. If the return type is json then the aligned face will be returned base64 encoded in the `b64_encoded_aligned` field. If the return type is an image then the two images will be horizontally concatenated and returned. 64 | 65 | 66 | ```python 67 | import requests 68 | 69 | url = "https://toonify.p.rapidapi.com/v0/toonify" 70 | query = { 71 | "face_index": 1, 72 | "return_aligned":"true", 73 | } 74 | headers = { 75 | "x-rapidapi-host": "toonify.p.rapidapi.com", 76 | "x-rapidapi-key": "KEY_HERE", 77 | "accept": "image/jpeg" 78 | } 79 | files = {"image": open("imagefile.jpg", "rb")} 80 | 81 | response = requests.request("POST", url, files=files, headers=headers, params=query) 82 | 83 | print(reponse.content) #will be the jpeg image bytes 84 | ``` 85 | 86 | ![](https://assets.justinpinkney.com/toonify/images/pair.jpeg) 87 | 88 | __Next take a look at the various options you have: [More Options](more-options)__ --------------------------------------------------------------------------------