sketchpy
sketchpy copied to clipboard
Do you want to draw some cool pictures with a few lines of Python code? SketchPy is here to help..Sketchpy is a Python module for animating drawings of images. The sketchpy module is created on top of...
Welcome to sketchpy
Description
This is the Intermediate level python project to do some awesome drawing animation using the turtle module, hope it grows in the future.
It is a Python module for animating drawings of images. The sketchpy module is created on top of the turtle module in Python.
To install sketchpy on your computer, you can go to your command prompt (command line) and run the following command.
Usage
- Just install the package
pip install sketchpy3 - Followed by
pip install --upgrade sketchpy3to update the package to the latest version. - Import it to you project
import sketchpy3and use as you want😊
Built with
- Turtle
- Open-cv
- Pillow
- numpy
- Svgpathtools
Getting started
Lastes version of sketchpy: 0.1.8
- you can install the latest version with either
pip install sketchpy3==0.3.1
or
pip install sketchpy3 --U
Updates!!
-
Now uses
AIto generate different styles of images for sketching using the classcanvas.ai_sketch_from_image -
You can use the function as followes
from sketchpy3 import canvas if __name__ == "__main__": obj = canvas.ai_sketch_from_image(IMG_PATH,3) obj.draw() -
Sample
- The first image is the
source image, and the following corresponds to different styles from[0-3] - This version
0.3.1uses multiprocessing for processing the single svg file in 4 different threads to reduce the time for loading the svg file - Sample
- And I have included a new function named
get_svg()fromcanvasto convert your Image to svg, - You can use the function as followes
from sketchpy import canvas canvas.get_svg(img_path) - The
get_svg()function opens a short url onlyoncea day. Just enter the 4 digit number from the landing page from the short url in the cmd to access the svg converter. And you need to complete the short url only once a day, So it's no big deal.
Prerequisites
- Python
- Basic text editor
- creativity😂
Install
pip install sketchpy3
it should probably work, If not then try the following code
pip install turtle open-cv wheel sketchpy3
Trace from Image
The recent version of the package includes a class named trace_from_image(), which allowes you to get the same output as using a svg file without the need to convert it to a svg file. hecnce it reduces the run time and it is much effecient.
- To know more about this new class visit the blog post here.
- A sample output of the class
trace_from_image(). - you can take a view about how the class working in here
Sample Code:
from sketchpy3 impor canvas
obj = canvas.trace_from_image("Image Path")
obj.draw()
Parameters :
- Path: Path of the image
- Scale:
-scaling factor for the sketched image,
- less than 1 => smaller than original image
- equal to 1 => original size
- greater than 1 => greater than original image
- intensity -> intensity of details, keep the value between 0 and 255, optimal value lies between(200 - 255)
- save -> take a screenshot when the program stops sketching, false by default
- details -> use to skip the small details from the image to increase the speed. details=0 -> inculde all minor details, details=50 -> include all details which are greater than 50
- blur -> always provide a odd number, the lower the value the more distortion, higher the value the more smooth, optimal value 51
- skip_frequency -> used to speed the sketchpy the process by skipping some values
Sketch from Image
used to trace the image line by line.
Example Code :
from sketchpy impor canvas
obj = canvas.sketch_from_image("Image Path")
obj.draw(threshold = 127)
Parameters
- path -> path of the image
- save -> used to same the results
you can watch the example video from here
NOTE: you can change the value of threshold to draw more detailed image, it's range is 0 - 255,use values between 90-190
to know more about it visit here
Drawing From SVG file
You can sketch image uinsg the class color_sketch_from_svg, which takes the inpu in svg formate and then sketches it.
Example Code:
from sketchpy3 impor canvas
if __name__ == "__main__":
obj = canvas.color_sketch_from_svg("Image Path")
obj.draw()
Example output
NOTE: sketch_from_svg class is remove from the package, since it can only draw with single color, color_sketch_from_svg class will be available.
Parameters
- color_sketch_from_svg
- path -> path of the svg file
- no_of_processes -> no of individual branches the process the svg file
- scale -> zoom value
- x_offset -> amount of movemnt in x direction
- y_offset -> amount of movemnt in y direction
- save -> (True by defaule)= take a screenshot and save it
- load_svg
- file_name -> name of the npy array, you can use this array data to sketch images directly
- draw
- retain -> retain the window after sketching (true by defaule)
- file -> file path of the npy file for direct sketching
- data -> raw data, should be a list in [[[x1,y1], [x2,y2], ....], [255,255,255]], first nested list is the points and the second list the color
- x_offset -> amount of movement in x direction while sketching
- y_offset -> amount of movement in y direction while sketching
- scale -> zoom value while sketching
- speed -> speed of sketching
Sketching form .npy file
Insted of waiting for the svg file to load, you can saved .npy file and use that for future use,
use the following code to draw your image from saved data file
from sketchpy3 import canvas
obj = canvas.color_sketch_from_svg(None)
obj.draw(file = 'data.npy')
Converting Image to SVG formate
Sketchpy3 requires specific type of SVG file formate to work properly, hence this version includes a standalone svg converter function with it
use the follow code to convert you images to svg files
from sketchpy3 import canvas
canvas.get_svg(IMG_PATH)
- It takes the image from the
IMG_PATHand converts it into an svg file - But to access this SVG converter you have to complete a shorturl, don't worry you need to do this only once a day
- Use brave browser to complete it with ih 20 sec.
Converting Image to AI ART
-
This new version sketchpy3 includes a class named
ai_sketch_from_image -
This class converts the given imag to different styles of image using
generative artfrom bryandlee/animegan2 -
You can use it as follows
from sketchpy3 import canvas if __name__ == "__main__": obj = canvas.ai_sketch_from_image(IMG_PATH, STYLE_INDEX) obj.draw()
Use the following code to get the AI ART as image
```
from sketchpy3 import canvas
obj = canvas.ai_sketch_from_image(IMG_PATH, STYLE_INDEX)
obj.convert_image()
```
- You can find your output image as
source.jpgfile
Example
Parameters
- ai_sketch_from_image
- path -> path of the svg file
- style_index -> [0-3] each number produces different styles of image
- no_of_processes -> no of individual branches the process the svg file
- scale -> zoom value
- x_offset -> amount of movemnt in x direction
- y_offset -> amount of movemnt in y direction
- save -> (True by defaule)= take a screenshot and save it
- load_svg
- file_name -> name of the npy array, you can use this array data to sketch images directly
- draw
- retain -> retain the window after sketching (true by defaule)
- file -> file path of the npy file for direct sketching
- data -> raw data, should be a list in [[[x1,y1], [x2,y2], ....], [255,255,255]], first nested list is the points and the second list the color
- x_offset -> amount of movement in x direction while sketching
- y_offset -> amount of movement in y direction while sketching
- scale -> zoom value while sketching
- speed -> speed of sketching
Library Example
Open your code editor and write the example Python code snippets given below. Run your code and see the magic by yourself.
Drawing Robert Downey Jr. Using Python
from sketchpy3 import library as lib
obj = lib.rdj()
obj.draw()
OUTPUT
Drawing Tom Holland Using Python
from sketchpy3 import library
myObject = library.tom_holland()
myObject.draw()
OUTPUT
More examples
from sketchpy3 import library as lib
obj = lib.bts()
obj.draw()
from sketchpy3 import library as lib
obj = lib.vijay()
obj.draw()
Drawing Iron Man ASCII Animation Using Python
from sketchpy3 import library
myObject = library.ironman_ascii()
myObject.draw()
OUTPUT
Troubleshooting
- If you find any problem, you can pull request, or contact me on either insta or discord
- You can also find video on my youtube channel
- You can know more about sketchpy and get tutorial in this blog page
Acknowledgements
Thanks to all who helped inspire this project.❤
See also
Consider supporting me
- we spend
hoursto implement these algorithms and making you to access these with just 3 lines - consider
supportingour work. - even a single
rupeeconunts. - upi id
sriramanand23@okicici - scan and encourage us to develop more features or use the
short urlto get the svg file

License
This project is licensed under the MIT License.