What Size Mono Line For Fly Line Loop Repair
Cartoon Shapes on Images with Python and Pillow
Pillow provides a drawing module called If you need more advanced cartoon capabilities than what is included in Pillow, you lot tin can become a split up package chosen aggdraw. You will focus on what comes with Pillow in this article. Specifically, you will learn most the following: When cartoon with Pillow, it uses the aforementioned coordinate system that you have been using with the rest of Pillow. The upper left corner is all the same (0,0), for case. If you draw exterior of the epitome bounds, those pixels will exist discarded. If you lot want to specify a color, you can use a series of numbers or tuples as you lot would when using When you get to utilise the various drawing methods, you will discover that they have a lot of common parameters that they share. Rather than explain the aforementioned parameters in every department, y'all will larn nigh them up-front end! Most of the cartoon methods take an When it comes to cartoon a line, polygon, or point, multiple coordinates are specified in either of these ways: The The parameter, The default is The The default is Now that yous know about the common parameters, you lot can move on and larn how to beginning drawing! The kickoff type of cartoon you will acquire about is how to depict lines in Pillow. All shapes are made upwardly of lines. In Pillow'due south example, a line is drawn by telling Pillow the showtime and catastrophe coordinates to draw the line between. Alternatively, you can pass in a series of XY coordinates and Pillow will draw lines to connect the points. Following is the You can run into that it accepts several different parameters. Y'all learned what some of these parameters mean in the previous section. The Before y'all learn how to utilise At present go open up your Python editor and create a new file named Hither you lot open the epitome in Pillow and and then laissez passer the Yous apply the At present you tin try creating a series of points and cartoon lines that way. Create a new file named This time you lot create an image using Pillow rather than drawing on one of your own. Then you create a list of points. To brand the line connections look nicer, you can set the When you run this lawmaking, your image will wait like this: Now try removing the By setting Now you're ready to learn about drawing arcs with Pillow! An arc is a curved line. You lot can draw arcs with Pillow too. Hither is the An To run across how you might describe an arc, create a new file named In this code, yous create a new epitome with a white groundwork. And so you create your When yous run this lawmaking, your output epitome will look like this: Try irresolute some of the parameters and re-running the code to run into how you can change the arcs yourself. Now let's move on and learn about drawing chords! Pillow also supports the concept of chords. A chord is the same as an arc except that the endpoints are connected with a directly line. Hither is the method definition of The simply deviation here is that you can also add an Create a new file and name information technology This example will depict ii chords on a light-green image. The first chord is filled in with a red color. The second chord is filled in with xanthous only is outlined in bluish. The blue outline has a width of v. When you run this code, yous will create the following epitome: That looks pretty good. Become alee and play around with this case too. You lot'll soon master chord making with Pillow with a picayune do. Now let's keep and larn most drawing ellipses! An ellipse, or oval, is drawn in Pillow by giving information technology a bounding box (xy). Y'all take seen this several other times in previous sections. Here is the The To see how you lot tin create an In this code, you create a dainty white epitome via the When you run this code, the image it creates will await like this: Y'all can create ovals and circles using Now let's find out how to create pie slices! A pie slice is the same as Here is how the You have used all of these parameters in other drawings. To review, To first practicing this shape, create a new file named In this code, y'all generate a grey image to draw on. Then you create two pie slices. The first When yous run this code, you volition get the following paradigm: With a footling work, you could create a pie graph using Pillow! You should play effectually with your code a flake and change some values. You will quickly learn how to make some nice pie slices of your own. Now let'southward find out how to draw polygons with Pillow! A polygon is a geometric shape that has a number of points (vertices) and an equal number of line segments or sides. A square, triangle, and hexagon are all types of polygons. Pillow lets you create your own polygons. Pillow's documentation defines a polygon like this: The polygon outline consists of straight lines between the given coordinates, plus a direct line betwixt the concluding and the first coordinate. Here is the code definition of the All of these parameters should be familiar to you now. Go alee and create a new Python file and name it This code volition create a grey image like the terminal example in the previous section. It will then create a polygon that is filled with the color dark-green. And then it volition create a 2d polygon and outline information technology in xanthous without filling information technology. In both of the drawings, you are supplying 3 points. That will create ii triangles. When you run this lawmaking, you lot will get this output: Attempt changing the code by adding additional points to one or more of the polygons in the code in a higher place. With a little do, you'll be able to create complex polygons quickly with Pillow. The Yous can laissez passer in ii tuples that define the commencement and ending coordinates to describe the rectangle. Or you can supply the iv coordinates as a box tuple (iv-item tuple). And so y'all can add an Create a new file and name it This code volition create a bluish image that is 400x400 pixels. Then information technology volition draw two rectangles. The offset rectangle volition be filled with red. The second volition be filled with green and outlined with yellow. When you run this code, you lot will become this image as output: Aren't those lovely rectangles? You can alter the rectangle's points to create thinner or wider rectangles. You could also modify the outline width that y'all add to the rectangles. You lot can use Pillow to add shapes to your images. This can be helpful for adding outlines to your images, highlighting 1 or more portions of your image, and more. In this article, you learned well-nigh the following topics: Yous can practice a lot with the shapes that are provided by Pillow. You should have these examples and change them to examination them out with your ain photos. Requite it a try and see what you lot can come up up with!ImageDraw
that you can use to create simple 2nd graphics on your Image
objects. According to Pillow's documentation, "you can use this module to create new images, comment or retouch existing images, and to generate graphics on the fly for web use."
PIL.Epitome.new()
. For "i", "L", and "I" images, use integers. For "RGB" images, use a iii-tuple containing integer values. You may likewise utilize the color names that are supported past Pillow that y'all learned almost in chapter two.Mutual Parameters
xy
xy
parameter that sets a rectangular area in which to draw a figure. This tin be defined in the following two means:
(x1, y1, x2, y2, x3, y3...)
((x1, y1), (x2, y2), (x3, y3)...)
line()
method will describe a straight line, connecting each point. The polygon()
will draw a polygon where each point is connected. Finally, the point()
will draw a indicate of one-pixel at each point.make full
make full
, is used to prepare the colour that will make full the shape. The mode you set the fill
is determined by the manner of the image:
RGB
: Ready each color value (0-255) using (R, One thousand, B) or a color proper nounL
(grayscale): Prepare a value (0-255) equally an integerNone
or no fill.outline
outline
sets the border color of your drawing. Its specification is the same as the one yous use for fill
.None
, which means no border.Drawing Lines
line()
method definition:def line(self, xy, fill=None, width=0, articulation=None): """Draw a line, or a connected sequence of line segments."""
width
parameter is used to control the width of the lines.joint
, y'all should learn how to draw lines without it. But first, you will need an image to draw on. You lot will use this epitome of 1 of the Madison County bridges:draw_line.py
and add this lawmaking to it:# draw_line.py import random from PIL import Image, ImageDraw def line(image_path, output_path): image = Prototype.open(image_path) draw = ImageDraw.Draw(image) colors = ["red", "light-green", "blue", "yellow", "majestic", "orange"] for i in range(0, 100, 20): draw.line((i, 0) + epitome.size, width=five, fill=random.choice(colors)) image.save(output_path) if __name__ == "__main__": line("madison_county_bridge_2.jpg", "lines.jpg")
Image
object to ImageDraw.Draw()
, which returns an ImageDraw
object. Now you tin can draw lines on your image. In this case, yous use a for
loop to draw five lines on the prototype. The showtime image starts at (0,0) in the starting time loop. Then the X position changes in each iteration. The endpoint is the size of the image.random
module to cull a random color from a listing of colors. When you run this code, the output volition look something like this:draw_jointed_line.py
and put this lawmaking in your file:# draw_jointed_line.py from PIL import Image, ImageDraw def line(output_path): image = Image.new("RGB", (400, 400), "cherry") points = [(100, 100), (150, 200), (200, l), (400, 400)] depict = ImageDraw.Describe(paradigm) depict.line(points, width=15, fill="green", articulation="curve") image.salve(output_path) if __name__ == "__main__": line("jointed_lines.jpg")
joint
parameter to "bend". If you await at the source code for the line()
method, you volition find that "curve" is the just valid value to requite information technology other than None
. This may alter in a future version of Pillow.articulation
parameter from your lawmaking and re-run the case. Your output will now look like this:articulation
to "bend", the output will be slightly more pleasing to the eye.Drawing Arcs
arc()
method specification:def arc(cocky, xy, showtime, end, make full=None, width=ane): """Describe an arc."""
arc()
tin can also be made using xy
points. The start
parameter defines the starting angle, in degrees. The cease
parameter tells Pillow what the ending angle is, which is also in degrees. The other two parameters are ones that have already been introduced.draw_arc.py
and add this code to it:# draw_arc.py from PIL import Prototype, ImageDraw def arc(output_path): image = Epitome.new("RGB", (400, 400), "white") draw = ImageDraw.Draw(image) draw.arc((25, fifty, 175, 200), starting time=30, terminate=250, fill="green") draw.arc((100, 150, 275, 300), offset=20, end=100, width=5, fill="yellow") image.salvage(output_path) if __name__ == "__main__": arc("arc.jpg")
Draw
object. Next, yous create two unlike arcs. The start arc will be filled with green. The second arc will be filled in yellowish, simply its line width volition be 5. When you lot draw an arc, the fill is referring to the arc's line colour. Yous aren't filling the arc itself.Drawing Chords
chord()
:def chord(self, xy, start, end, fill=None, outline=None, width=1): """Depict a chord."""
outline
color. This colour can be specified in whatever of the ways that you can specify a fill
color.draw_chord.py
. So add together this code and so you can see how you make chords yourself:# draw_chard.py from PIL import Image, ImageDraw def chord(output_path): image = Image.new("RGB", (400, 400), "green") draw = ImageDraw.Describe(paradigm) draw.chord((25, l, 175, 200), start=thirty, end=250, fill="red") describe.chord((100, 150, 275, 300), start=20, end=100, width=five, fill="yellow", outline="bluish") prototype.salve(output_path) if __name__ == "__main__": chord("chord.jpg")
Drawing Ellipses
ellipse()
method definition:def ellipse(self, xy, fill up=None, outline=None, width=1): """Draw an ellipse."""
ellipse()
lets you fill up it with a colour, add a colored border (outline
) and alter the width
of that outline
.ellipse()
, make a new file named draw_ellipse.py
and add this lawmaking to it:# draw_ellipse.py from PIL import Image, ImageDraw def ellipse(output_path): paradigm = Prototype.new("RGB", (400, 400), "white") draw = ImageDraw.Draw(image) draw.ellipse((25, l, 175, 200), fill="red") depict.ellipse((100, 150, 275, 300), outline="black", width=5, fill="yellow") image.relieve(output_path) if __name__ == "__main__": ellipse("ellipse.jpg")
new()
method. And then you depict a red ellipse on summit of it. Finally, you lot depict a 2d ellipse that is filled with yellow and outlined in black where the outline width is gear up to 5.ellipse()
. Give information technology a try and see what yous can do with it.Cartoon Pie Slices
arc())
, just also draws straight lines between the endpoints and the center of the bounding box.pieslice()
method is divers:def pieslice(cocky, xy, start, end, fill up=None, outline=None, width=1): """Describe a pieslice."""
fill
adds color to the inside of the pieslice()
while outline
adds a colored border to the figure.draw_pieslice.py
and add together this code to your file:# draw_pieslice.py from PIL import Prototype, ImageDraw def pieslice(output_path): image = Image.new("RGB", (400, 400), "grey") draw = ImageDraw.Depict(image) draw.pieslice((25, 50, 175, 200), get-go=30, terminate=250, fill up="green") depict.pieslice((100, 150, 275, 300), start=xx, end=100, width=5, outline="yellow") image.save(output_path) if __name__ == "__main__": pieslice("pieslice.jpg")
pieslice()
is filled in with green. The second one is not filled in, but it does accept a yellow outline
. Annotation that each pieslice()
has a different starting and ending degree.Drawing Polygons
polygon()
method:def polygon(self, xy, make full=None, outline=None): """Draw a polygon."""
draw_polygon.py
. Then add this code:# draw_polygon.py from PIL import Image, ImageDraw def polygon(output_path): image = Epitome.new("RGB", (400, 400), "grey") describe = ImageDraw.Draw(image) draw.polygon(((100, 100), (200, fifty), (125, 25)), fill="green") draw.polygon(((175, 100), (225, 50), (200, 25)), outline="xanthous") image.save(output_path) if __name__ == "__main__": polygon("polygons.jpg")
Drawing Rectangles
rectangle()
method allows you lot to draw a rectangle or square using Pillow. Here is how rectangle()
is defined:def rectangle(self, xy, fill=None, outline=None, width=1): """Draw a rectangle."""
outline
, fill
it with a color, and change the outline'south width
.draw_rectangle.py
. Then fill it in with this code and then you can start cartoon rectangles:# draw_rectangle.py from PIL import Image, ImageDraw def rectangle(output_path): image = Epitome.new("RGB", (400, 400), "blueish") draw = ImageDraw.Describe(paradigm) describe.rectangle((200, 100, 300, 200), fill up="red") describe.rectangle((50, fifty, 150, 150), fill="dark-green", outline="yellow", width=3) image.save(output_path) if __name__ == "__main__": rectangle("rectangle.jpg")
Wrapping Up
Related Reading
Pillow: Paradigm Processing with Python
Buy now on Leanpub
Source: https://www.blog.pythonlibrary.org/2021/02/23/drawing-shapes-on-images-with-python-and-pillow/
Posted by: kernrourts.blogspot.com
0 Response to "What Size Mono Line For Fly Line Loop Repair"
Post a Comment