Dimensions for PIL#
DimLinesPIL package#
Dimension Toolbox for PIL
Dimensions with associated extenders and leaders dimension.py line with arrows used as base for other dimensions
- DimLinesPIL.DashedLine(dr, start_pos, end_pos=None, dash=(5, 5), angle=None, size=None, width=1, fill=(0, 0, 0))#
Create dashed lines in PIL.
- Parameters:
dr (str) -- PIL drawing handle
start_pos (int) -- starting coordinate tuple
end_pos (int) -- finishing coordinate tuple, optional
dash (int) -- tuple of line pattern
angle (int) -- slope of line degrees, optional
size (int) -- line size
width (int) -- line width
fill (int) -- colour tuple
- Return type:
dashed line
- DimLinesPIL.angled_text(im, at, text, angle, font, fill='black', aall=1)#
Text drawn at an angle, text position in centre of text.
- Parameters:
im (str) -- PIL image handle
at (int) -- coordinate tuple, text position
text (str) -- text input
angle (float) -- text angle (degrees)
font (str) -- font to be used
fill (int) -- text colour tuple
aall (int) -- unconstrained or angle constrained, default 1 unconstrained
- Returns:
im -- PIL image handle
- Return type:
str
- DimLinesPIL.arc_dim(im, dr, centre, radius, begin, end, fill=(0, 0, 0), text=None, font=None, arrowhead=(8, 10, 3))#
Draw arc dimension based on centre and radius
- Parameters:
dr (str) -- PIL image handle
dr -- PIL drawing handle
centre (int) -- coordinate tuple
radius (int) -- radius of arc
begin (int) -- starting angle degrees
end (int) -- finishing angle degrees
fill (int) -- colour tuple
text (str) -- arc text
font (str) -- text font
arrowhead (int) -- tuple arrow size and shape
- Return type:
arc dimension
- DimLinesPIL.bres(dr, ptA, ptB, fill='black')#
Use integer coordinates on the line from (x0, y0) to (x1, y1). Input coordinates should be integers. The result contains both the start and the end point.
- Parameters:
dr (str) -- PIL drawing handle
ptA (int) -- coordinate tuple at line start
ptB (int) -- coordinate tuple at line finish
fill (str or int) -- line colour name, hash or tuple
- DimLinesPIL.cart2polar(centre, outer)#
Convert cartesian coordinates to polar
- Parameters:
centre (int) -- coordinates for central point
outer (int) -- coordinates for outer point
- Return type:
polar tuple degrees and ray (length)
- DimLinesPIL.create_arc(dr, c, r, start, end, fill='black')#
Returns arc using centre and radius
- Parameters:
dr (str) -- PIL draw handle
c (int) -- centre coordinate tuple
r (int) -- radius of enclosing circle
start (int) -- starting angle degrees
end (int) -- finishing angle degrees
fill (int) -- colour tuple of filled arc
int (outline =) -- colour tuple of arc outline
- Return type:
arc drawing
- DimLinesPIL.dim_level(im, dr, at, diam, ldr=20, dash=(10, 4), text=None, fill='black', tri=8)#
Level dimension, dashed diameter, leader from surface to wall
at on left tank wall, diam internal tank diameter,
triangle on top of level (8,8,8) p0 tip triangle, p1, p2 angles, p2 on at-p4 p3 opposite side to at, both drawn to inside tank wall
leader (ldr) at 60° up to p4 then horizontal to p5
- Parameters:
im (str) -- PIL image handle
dr (str) -- PIL drawing handle
at (int) -- coordinate tuple left hand tank wall
diam (int) -- internal tank diameter
ldr (int) -- leader length from surface
dash (int) -- dash pattern
text (str) -- level text
fill (int) -- colour tuple
tri (int) -- size equilateral triangle at surface
- Returns:
im -- PIL image handle
- Return type:
str
- DimLinesPIL.dimension(dr, ptA, ptB=None, angle=None, width=1, fill=(0, 0, 0), arrowhead=(8, 10, 3), arrow='last')#
Creates a line with an arrow at one or both ends, basis for other scripts.
Enter two coordinates for line, or one coordinate and angle for just an arrow.
Arrowhead tuple gives size and shape of arrow.
Arrow gives relative position arrow on line.
- Parameters:
dr (str) -- PIL drawing handle
ptA (int) -- coordinate tuple at line start
ptB (int, optional) -- coordinate tuple at line end
angle (float, optional) -- line angle (degrees)
width (int) -- line width
fill (int) -- line colour tuple
arrowhead (int) -- tuple arrow size and shape
arrow (str) -- arrow position 'first', 'last' or 'both'
- Return type:
draws line with one or two arrows either end or just an arrow
- DimLinesPIL.dims(im, dr, ptA, ptB, extA, extB=None, text=None, font=None, textorient=None, fill=(0, 0, 0), tail=True, arrowhead=(8, 10, 3), arrow='both')#
Dimension vertical and horizontal tailed lines with extender lines, option to use arrows.
Extenders can be integer or tuple of line and gap size
Extenders can be unequal length, if extB excluded same size.
Extenders positive right when vertical, above when horizontal
- Parameters:
im (str) -- PIL image handle
dr (str) -- PIL drawing handle
ptA (int) -- starting coordinate tuple
ptB (int) -- ending coordinate tuple
extA (int) -- integer size of extender at starting point or tuple of line and gap
extB (int) -- size of extender at finishing point, optional
text (str) -- dimension text
font (str) -- text font
textorient (str) -- 'vertical' or 'horizontal', optional
fill (int) -- colour tuple
tail (bool) -- 'True' default show tails on dimension line, 'False' use arrows
arrowhead (int) -- tuple arrow size and shape
arrow (str) -- arrow position 'first', 'last' or 'both' default
- Return type:
outside dimension
- DimLinesPIL.inner_dim(im, dr, ptA, ptB, text=None, font=None, width=1, fill='black', arrowhead=(8, 10, 3), arrow='both')#
Used on horizontal or vertical inner dimensions.
- Parameters:
im (str) -- PIL image handle
dr (str) -- PIL drawing handle
ptA (int) -- tuple starting coordinates
ptB (int) -- tuple finishing coordinates, optional
text (str) -- text
font (str) -- text font
width (int) -- line width
fill (int) -- colour tuple
arrowhead (int) -- tuple size and shape arrow
arrow (str) -- position arrow, 'first', 'last' or 'both'
- Return type:
inner dimension
- DimLinesPIL.int_up(x)#
Decimal part of number rounded up if greater than .5 if positive otherwise rounded down.
- Parameters:
x (float)
- Return type:
int
- DimLinesPIL.leader(im, dr, at, angle=315, extA=20, extB=20, width=1, arrowhead=(3, 5, 1), arrow='first', fill='black', text=None, font=None)#
Leader to object
angle and length (extA) first part
horizontal length for second part (extB)
- Parameters:
im (str) -- PIL image handle
dr (str) -- PIL drawing handle
at (int) -- coordinate tuple start of leader
angle (int) -- slope of first part, angle changes the leader
extA (int) -- length line in first part
extB (int) -- length line in second part
width (int) -- line width
arrowhead (int) -- tuple size and shape arrow
arrow (str) -- position arrow, normally 'first'
fill (int) -- tuple to show colour
text (str) -- descriptive text
font (str) -- text font
- Return type:
leader
- DimLinesPIL.polar2cart(centre, phi, ray, units='degrees')#
Convert polar to cartesian coordinates
- Parameters:
centre (int) -- coordinate tuple
phi (float) -- angle of ray (degrees or radians)
ray (int) -- distance from centre
units (str) -- angle units in 'degrees' or 'radians'
- Returns:
x, y -- coordinate tuple
- Return type:
int
- DimLinesPIL.slant_dim(im, dr, ptA, ptB=None, extA=None, angle=None, size=None, fill='black', text=None, font=None)#
Used on slanting dimensions, with 45" tails.
Extenders can be integer or tuple of line and gap size
Extenders positive left when vertical, above when horizontal
- Parameters:
im (str) -- PIL image handle
dr (str) -- PIL drawing handle
ptA (int) -- tuple starting coordinates
ptB (int) -- tuple finishing coordinates, optional
extA (int) -- integer or tuple of extender length, second entry space
extB (int) -- integer or tuple of extender length, second entry space, optional
angle (int) -- slope line, optional
size (int) -- length dimension, optional
text (str) -- text
font (str) -- text font
width (int) -- line width
fill (int) -- colour tuple
- Return type:
slanting dimension
- DimLinesPIL.thickness_dim(im, dr, ptA, thick, angle=0, text=None, font=None, width=1, fill='black', arrowhead=(8, 10, 3), arrow='last')#
Horizontal or vertical dimension to show thickness of object.
It will be drawn with two inwardly pointing arrows, and text placed outside of the object.
- Parameters:
im (str) -- PIL image handle
dr (str) -- PIL drawing handle
ptA (int) -- starting coordinate tuple
thick (int) -- thickness of object in pixels
angle (int) -- angle of dimension, in degrees
text (str) -- dimension text
font (str) -- text font
width (int) -- line width
fill (int) -- colour tuple
arrowhead (int) -- tuple arrow size and shape
arrow (str) -- arrow position 'first' or 'last' the default
- Return type:
thickness dimension