AA Dimensions with PIL#

DimLinesAA package#

Antialiased Dimension Toolbox for PIL

Antialiased dimensions with associated extenders and leaders dimension_aa.py line with arrows used as base for other dimensions

Use this to make arrowhead on the end of lines tuple (d1, d2, d3) specifies shape, default (8, 10, 3) d1 specifies length along the line d2 is the äong side d3 is the vertical height

make linear dimension with option for arrows both ends or one end only arrow='first', arrow='last', arrow='both'

dimension_aa normal dimensioning, used as base for other dimensions arc_dim_aa dimension over an angle

  • to_matrix,

    changes list to 2D list

  • above_below,

    cross product to determine on which side a point liesrelative to line

  • centroid,

    finds centroid from list 2D points

  • flood,

    fills a space with a colour

  • findSect,

    finds sector (Octant) and quadrant

  • plot_sector_points,

    8-way plot with sector switch

  • DashedLineAA

    one pixel wide dashed aa line

  • WideLineAA,

    normal thick aa line

  • LineAA,

    one pixel wide normal aa line

  • PartLineAA,

    one pixel wide aa line which can switch off aa on one or other side

  • polyAA,

    draws aa polygon

  • PartCircleAA,

    aa arc with start and finish

  • dimension_aa,

    basic aa line with arrows either end

  • dims_aa,

    outer dimension vertical and horizontal tailed lines with extension lines

  • inner_dim_aa,

    inner vertical and horizontal dimensions

  • thickness_dim_aa,

    thickness dimension

  • make_arc_aa,

    driving routine for arcs

  • arc_dim_aa,

    angle dimension

  • leader_aa,

    leader to object

  • slant_dim_aa,

    slanting dimension with 45° tails

  • level_dim_aa,

    leader to triangle on tank level

DimLinesAA.DashedLineAA(dr, ptA, ptB, dash=(5, 5), fill=(0, 0, 0), back=(255, 255, 221), adjust=False)#

Makes dashed antialiased line, 1 pixel wide

Parameters:
  • dr (str) -- PIL drawing handle

  • ptA (int) -- coordinate tuple at line start

  • ptB (int) -- coordinate tuple at line end

  • dash (int) -- tuple of dash and space sizes, if single integer then dash and space sizes of equal size, default (5,5)

  • fill (int) -- rgb line colour tuple, default black

  • back (int) -- rgb background colour tuple, default light straw

  • adjust (bool) -- line and gap sizes adjusted to slope, default False

Return type:

thick antialiased line selected colour

DimLinesAA.LineAA(draw, ptA, ptB, fill=(0, 0, 0), back=(255, 255, 255))#

Draw a dark antialiased one pixel wide line on light background,

Parameters:
  • draw (str) -- PIL drawing handle

  • ptA (int) -- coordinate tuple at line start

  • ptB (int) -- coordinate tuple at line end

  • fill (int) -- rgb line colour tuple, default black

  • back (int) -- rgb background colour tuple, default light straw

Return type:

thin antialiased line selected colour

DimLinesAA.PartCircleAA(dr, xm, ym, r, start, finish, width, sects, fill=(0, 0, 0), back=(255, 255, 221))#

Draw a thick antialiased arc on light background, using polar attributes, either specify start and finish angles or end coordinates of enclosing lines starting at arc centre.

Parameters:
  • dr (str) -- PIL drawing handle

  • xm (int) -- x coordinate of circle centre

  • ym (int) -- y coordinate of circle centre

  • r (int) -- circle radius in pixels

  • start (int) -- angle in degrees, or cooedinate tuple of enclosing line

  • finish (int) -- angle in degrees, or cooedinate tuple of enclosing line

  • width (int) -- arc width in pixels

  • sects (int) -- sector numbers in tuple for start and finish

  • fill (int) -- rgb arc colour tuple, default black

  • back (int) -- rgb background colour tuple, default light straw

Return type:

thick antialiased arc selected colour

DimLinesAA.PartLineAA(draw, ptA, ptB, fill=(0, 0, 0), back=(255, 255, 221), cross=0)#

Draw a dark antialiased one pixel wide line on light background, cross disables antialiasing on one side

Parameters:
  • draw (str) -- PIL drawing handle

  • ptA (int) -- coordinate tuple at line start

  • ptB (int) -- coordinate tuple at line end

  • fill (int) -- rgb line colour tuple, default black

  • back (int) -- rgb background colour tuple, default light straw

  • cross (int) -- cross disables antialiasing on one side, default 0 enables full antialiasing

Return type:

thin antialiased line selected colour

DimLinesAA.WideLineAA(draw, ptA, ptB, fill=(0, 0, 0), width=1, back=(255, 255, 221))#

Makes thick antialiased line

Parameters:
  • draw (str) -- PIL drawing handle

  • ptA (int) -- coordinate tuple at line start

  • ptB (int) -- coordinate tuple at line end

  • width (int) -- line width in pixels

  • fill (int) -- rgb line colour tuple, default black

  • back (int) -- rgb background colour tuple, default light straw

Return type:

thick antialiased line selected colour

DimLinesAA.above_below(start, end, ptA)#

Finds the side on which a point lies relative to line from the cross product

Parameters:
  • start (int) -- tuple of line start coordinates

  • end (int) -- tuple of line end coordinates

  • ptA (int) -- tuple of point coordinates

Return type:

int, positive or negative depending on line side

DimLinesAA.arc_dim_aa(im, dr, centre, radius, begin, end, text=None, font=None, arrowhead=(8, 10, 3), width=1, fill=(0, 0, 0), back=(225, 225, 221), aall=0)#

User interface to draw an antialiased arc

Parameters:
  • dr (str) -- PIL drawing handle

  • centre (int) -- tuple of arc centre coordinates

  • radius (int) -- arc radius

  • begin (int) -- angle in degrees, or coordinate tuple of enclosing line

  • end (int) -- angle in degrees, or coordinate tuple of enclosing line

  • width (int) -- arc width in pixels

  • fill (int) -- rgb line colour tuple, default black

  • back (int) -- rgb background colour tuple, default light straw

  • aall (int) -- constrained angled text, default 0

DimLinesAA.centroid(points)#

From a 2D list of points of a polygon find the centroid, the arrow point is entered twice so that the centroid is positioned away from any line

Parameters:

points (int) -- 2D tuple of polygon coordinates

Return type:

centroid coordinates, int tuple

DimLinesAA.dimension_aa(im, dr, ptA, ptB=None, angle=None, fill=(0, 0, 0), back=(255, 255, 255), arrowhead=(8, 10, 3), arrow='last')#

Creates an antialiased 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:
  • im (str) -- PIL image handle

  • 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)

  • fill (int) -- rgb line colour tuple, default black

  • back (int) -- rgb background colour tuple, default light straw

  • arrowhead (int) -- tuple arrow size and shape, default (8, 10, 3)

  • arrow (str) -- arrow position 'first', 'last' or 'both', default 'last'

Return type:

draws antialiased line and arrows both or either end, or just an arrow

DimLinesAA.dims_aa(im, dr, ptA, ptB, extA, extB=None, text=None, font=None, textorient=None, fill=(0, 0, 0), back=(255, 255, 221), tail=True, arrowhead=(8, 10, 3), arrow='both')#

Dimension vertical and horizontal tailed lines with extender lines, option to use arrows.

ptA, ptB line coords,

extA, extB extension lines to measured item, positive to right when vertical or above it when horizontal Extenders can be unequal length, if extB excluded then same size.

Parameters:
  • im (str) -- PIL image handle

  • dr (str) -- PIL drawing handle

  • ptA (int) -- starting coordinate tuple

  • extA (int) -- integer size of extender at starting point or tuple of line and gap

  • ptB (int) -- ending coordinate tuple, optional

  • extB (int) -- size of extender at finishing point, optional

  • text (str) -- dimension text

  • font (str) -- text font

  • textorient (str) -- 'vertical' or 'horizontal', optional

  • 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

  • fill (int) -- rgb line colour tuple, default black

  • back (int) -- rgb background colour tuple, default light straw

Return type:

outside dimension, antialiased tails and arrows

DimLinesAA.findSect(centre, outer)#

Finds sector (Octant) and quadrant between two points

Parameters:
  • centre (int) -- coordinates from which the calcution is made, integer tuple

  • outer (int) -- coordinates to which the calcution is made, integer tuple

Return type:

sector (octant) number and quadrant number, int tuple

DimLinesAA.flood(im, dr, at, fill, back)#

Flood fills a space with a colour

Parameters:
  • im (str) -- PIL image handle

  • dr (str) -- PIL drawing handle

  • at (int) -- coordinates to start fill, integer tuple

  • fill (int) -- final area colour integer tuple

  • back (int) -- initial area colour, integer tuple

DimLinesAA.inner_dim_aa(im, dr, ptA, ptB, text=None, font=None, arrowhead=(8, 10, 3), arrow='both', fill=(0, 0, 0), back=(225, 225, 221))#

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

  • text (str) -- text

  • font (str) -- text font

  • arrowhead (int) -- tuple size and shape arrow

  • arrow (str) -- position arrow, 'first', 'last' or 'both'

  • fill (int) -- rgb line colour tuple, default black

  • back (int) -- rgb background colour tuple, default light straw

Return type:

inner dimension, antialiased arrowhead

DimLinesAA.leader_aa(im, dr, at, angle=315, extA=20, extB=20, arrowhead=(3, 5, 1), arrow='first', text=None, font=None, fill=(0, 0, 0), back=(255, 255, 221))#

Leader with one arrow to object

angle and length (extA) first part, then goes horizontal 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

  • arrowhead (int) -- tuple size and shape arrow

  • arrow (str) -- position arrow, normally 'first'

  • text (str) -- descriptive text

  • font (str) -- text font

  • fill (int) -- rgb line colour tuple, default black

  • back (int) -- rgb background colour tuple, default light straw

Return type:

leader

DimLinesAA.level_dim_aa(im, dr, at, diam, ext=0, ldrA=20, ldrB=20, dash=(10, 4), text=None, fill=(0, 0, 0), back=(255, 255, 221), tri=8, font=None)#

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

if ext != 0, p7 position of end of extender before touching tank wall

Parameters:
  • im (str) -- PIL image handle

  • dr (str) -- PIL drawing handle

  • at (int) -- coordinate tuple left hand tank wall

  • diam (int) -- internal tank diameter

  • ext (int) -- external extender outer level, default 0 acts as inner level

  • ldrA (int) -- inclined leader length from surface, if negative changes view

  • ldrB (int) -- horizontal leader length

  • tri (int) -- size equilateral triangle at surface

  • dash (int) -- dash pattern

  • text (str) -- level text

  • fill (int) -- rgb line colour tuple, default black

  • back (int) -- rgb background colour tuple, default light straw

Return type:

internal or external antialiased level

DimLinesAA.make_arc_aa(dr, centre, radius, start, finish, width=1, fill=(0, 0, 0), back=(255, 255, 221))#

Controls how the part circle makes na antialiased arc

Parameters:
  • dr (str) -- PIL drawing handle

  • centre (int) -- tuple of arc centre coordinates

  • radius (int) -- arc radius

  • start (int) -- angle in degrees, or cooedinate tuple of enclosing line

  • finish (int) -- angle in degrees, or cooedinate tuple of enclosing line

  • width (int) -- arc width in pixels

  • fill (int) -- rgb line colour tuple, default black

  • back (int) -- rgb background colour tuple, default light straw

DimLinesAA.plot_sector_points(dr, xm, ym, x, y, sects, fill, all8=1)#

Plots any one of 8 or only from one of 4 sectors in the while loop according to the activated sector

Parameters:
  • dr (str) -- PIL drawing handle

  • xm (int) -- x coordinate of circle centre

  • ym (int) -- y coordinate of circle centre

  • x (int) -- x coordinate of point relative to circle centre

  • ym -- y coordinate of point relative to circle centre

  • sects (int) -- sector number to be plotted

  • fill (int) -- rgb line colour tuple

  • all8 (int) -- plots all 8 sectors or only 4, default 1 plots in any sector

Return type:

arc plot in specified sector

DimLinesAA.polyAA(im, dr, xy, fill=(0, 0, 0), outline=None, back=(255, 255, 221))#

Creates polygon from xy list of consecutive points, normally filled otherwise only outline colour

Parameters:
  • im (str) -- PIL image handle

  • dr (str) -- PIL drawing handle

  • xy (int) -- list of polygon coordinate tuples

  • fill (int) -- rgb line colour tuple, default black

  • outline (int) -- rgb outline colour tuple, default None

  • back (int) -- rgb background colour tuple, default light straw

Return type:

polygon selected colour

DimLinesAA.slant_dim_aa(im, dr, ptA, ptB=None, extA=None, angle=None, length=None, text=None, font=None, fill=(0, 0, 0), back=(255, 255, 221))#

Used on slanting dimensions, with 45" tails. ptA point on item surface

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

  • length (int) -- length dimension, optional

  • text (str) -- text

  • font (str) -- text font

  • fill (int) -- rgb line colour tuple, default black

  • back (int) -- rgb background colour tuple, default light straw

Return type:

slanting dimension

DimLinesAA.thickness_dim_aa(im, dr, ptA, thick, angle=0, text=None, font=None, arrowhead=(8, 10, 3), fill=(0, 0, 0), back=(255, 255, 221))#

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

  • arrowhead (int) -- tuple arrow size and shape

  • fill (int) -- rgb line colour tuple, default black

  • back (int) -- rgb background colour tuple, default light straw

Return type:

thickness dimension

DimLinesAA.to_matrix(listo, n=2)#

Convert list to multidimensional list

Parameters:
  • listo (int) -- incoming integer list

  • n (int) -- number dimensions, default 2

Return type:

list, usually 2dimensional for coordinates