Skip to content

Commit 09ccada

Browse files
Merge pull request #324 from Tejas1510/toonify
toonify any image using open cv
2 parents 8403b58 + ddeea6d commit 09ccada

File tree

5 files changed

+67
-0
lines changed

5 files changed

+67
-0
lines changed

Python/ToonifyImage/Readme.MD

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Toonify a Given Image
2+
3+
## Introduction
4+
```
5+
This is a python application which takes a image as input and toonify it (make a cartoonist image of it) using https://deepai.org/machine-learning-model/toonify api.
6+
You can read more about the Api here : https://deepai.org/machine-learning-model/toonify
7+
```
8+
## Third Party Libraries Required :
9+
1. Request Module # to fetch given image
10+
2. shutil Module # to save image locally
11+
12+
## How to install above Library
13+
```
14+
pip install requests
15+
pip install shutil
16+
```
17+
## How to use it :
18+
1. Download or clone the repository
19+
2. Install Required Libraries
20+
4. Run toonify.py
21+
3. In command line add you api key which you will get by signing up on https://deepai.org/machine-learning-model/toonify
22+
5. you will be asked to give the path of image you want to toonify
23+
6. you will get the toonified image in the same directory
24+
25+
## Output
26+
27+
### Original image
28+
29+
![endpoint](https://github.com/Tejas1510/hacking-tools-scripts/blob/toonify/Python/ToonifyImage/images/rohit.png)
30+
31+
### Toonified image
32+
33+
![endpoint](https://github.com/Tejas1510/hacking-tools-scripts/blob/toonify/Python/ToonifyImage/images/output.jpg)
34+
35+
![built with love](https://forthebadge.com/images/badges/built-with-love.svg)
36+
37+
Check out my Github profile [Tejas1510!](https://github.com/Tejas1510)

Python/ToonifyImage/images/output.jpg

120 KB
Loading

Python/ToonifyImage/images/rohit.png

12.1 KB
Loading

Python/ToonifyImage/output.jpg

120 KB
Loading

Python/ToonifyImage/toonify.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import requests
2+
import shutil # to save image locally
3+
# taking the path of image
4+
imagePath=input("Please enter the path of image to toonify : ")
5+
#taking api key
6+
api_key=input("Please enter your api key")
7+
# using python request module to fetch the data
8+
r = requests.post(
9+
"https://api.deepai.org/api/toonify",
10+
files={
11+
'image': open(imagePath, 'rb'),
12+
},
13+
headers={'api-key': api_key}
14+
)
15+
y=r.json()
16+
# fetching the path of the image formed from json which we have got
17+
image_url=y['output_url']
18+
filename = image_url.split("/")[-1]
19+
# Open the url image
20+
r1 = requests.get(image_url, stream = True)
21+
# Check if the image was retrieved successfully
22+
if r1.status_code == 200:
23+
# Set decode_content value to True, otherwise the downloaded image file's size will be zero.
24+
r1.raw.decode_content = True
25+
# Open a local file with wb ( write binary ) permission.
26+
with open(filename,'wb') as f:
27+
shutil.copyfileobj(r1.raw, f)
28+
print('Image sucessfully Downloaded: ',filename)
29+
else:
30+
print('Image Couldn\'t be retreived')

0 commit comments

Comments
 (0)