### Install Font Source: https://www.drawbot.com/content/text/drawingText Installs a font from a given file path for the current process. ```APIDOC ## installFont ### Description Install a font with a given path and the postscript font name will be returned. The postscript font name can be used to set the font as the active font. Fonts are installed only for the current process. Fonts will not be accessible outside the scope of DrawBot. All installed fonts will automatically be uninstalled when the script is done. ### Method N/A (Function) ### Endpoint N/A (Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python # set the path to a font file path = "path/to/font/file.otf" # install the font fontName = installFont(path) # set the font font(fontName, 200) # draw some text text("Hello World", (10, 10)) # uninstall font uninstallFont(path) ``` ### Response #### Success Response (200) - **fontName** (str) - The PostScript name of the installed font. #### Response Example ```json { "fontName": "MyCustomFont-Regular" } ``` ``` -------------------------------- ### ImageObject Methods (O) Source: https://www.drawbot.com/genindex Lists ImageObject methods starting with 'O', such as offset, open, and opTile. ```APIDOC ## ImageObject Methods (O) ### Description Provides access to ImageObject manipulation methods starting with the letter 'O'. ### Methods - **offset()**: Applies an offset transformation. - **open()**: Opens an image file. - **opTile()**: Applies an opTile operation. - **overlayBlendMode()**: Applies the overlay blend mode. ``` -------------------------------- ### Python Variables and Case Sensitivity in DrawBot Source: https://www.drawbot.com/content/courseware Explains the concept of variables in Python as storage containers. This script demonstrates how to assign values (numbers and strings) to variables, perform operations with them, and covers rules for variable naming, including restrictions on starting with numbers and the use of underscores. It also highlights that variable names are case-sensitive and shows examples of valid and invalid naming. ```python a = 12 b = 15 c = a * b CAP = "a string" print(c) print(CAP) # variable names cannot start with a # number: #1a = 12 # variable names can contain numbers, # just not at the start: a1 = 12 # underscores are allowed: _a = 12 a_ = 13 # a-z A-Z 0-9 _ # everything is an object # this "rebinds" the name 'a' to a new # object: a = a + 12 # variable names are case sensitive # meaning that: x = 12 # is a different variable from X = 13 print(x) print(X) y = 102 # so this is an error: print(Y) ``` -------------------------------- ### Installed Fonts Source: https://www.drawbot.com/content/text/drawingText Lists all fonts installed on the system, optionally filtered by character support. ```APIDOC ## installedFonts ### Description Returns a list of all installed fonts. Optionally a string with supportsCharacters can be provided, the list of available installed fonts will be filtered by support of these characters. ### Method N/A (Function) ### Endpoint N/A (Function) ### Parameters #### Path Parameters None #### Query Parameters - **supportsCharacters** (str) - Optional. A string of characters to filter fonts by. #### Request Body None ### Request Example ```python # Example usage (conceptual, requires DrawBot environment) # all_fonts = installedFonts() # cyrillic_fonts = installedFonts(supportsCharacters='Привет') ``` ### Response #### Success Response (200) - **fonts** (list of str) - A list of font names. #### Response Example ```json [ "Arial", "Times New Roman", "MyCustomFont" ] ``` ``` -------------------------------- ### DrawBot: Text Rendering Source: https://www.drawbot.com/content/quickReference Provides examples of rendering text with specified fonts, sizes, colors, and stroke in DrawBot using Python. It also shows how to use textBox for multi-line text and measure text size. ```python newPage() print("pageCount:", pageCount()) text("Hello World", (10, 10)) fontSize(100) fill(1, 0, 0) stroke(0) strokeWidth(5) text("Hello World", (10, 20)) font("Times-Italic", 25) fill(0, .5, 1) stroke(None) textBox("Hello World " * 100, (10, 150, 300, 300)) print("textSize:", textSize("Hallo")) ``` -------------------------------- ### ImageObject Properties and Methods (P) Source: https://www.drawbot.com/genindex Lists ImageObject properties and methods starting with 'P', covering various transformations and effects. ```APIDOC ## ImageObject Properties and Methods (P) ### Description Provides access to ImageObject properties and manipulation methods starting with the letter 'P'. ### Properties & Methods - **pageCount**: Gets the total number of pages. - **pageCurlTransition()**: Applies a page curl transition. - **pageCurlWithShadowTransition()**: Applies a page curl transition with shadow. - **pages**: Accesses the pages of the document. - **paletteCentroid()**: Calculates the centroid of the color palette. - **palettize()**: Reduces the number of colors in the image. - **paragraphBottomSpacing()**: Sets bottom spacing for paragraphs. - **paragraphTopSpacing()**: Sets top spacing for paragraphs. - **parallelogramTile()**: Applies a parallelogram tile transformation. - **PDF417BarcodeGenerator()**: Generates a PDF417 barcode. - **pdfImage**: Gets the PDF representation of the image. - **personSegmentation()**: Segments people in the image. - **perspectiveCorrection()**: Corrects perspective distortion. - **perspectiveRotate()**: Rotates the image in perspective. - **perspectiveTile()**: Applies a perspective tile transformation. - **perspectiveTransform()**: Applies a perspective transformation. - **perspectiveTransformWithExtent()**: Applies a perspective transformation with extent. - **photoEffectChrome()**: Applies the Chrome photo effect. - **photoEffectFade()**: Applies the Fade photo effect. - **photoEffectInstant()**: Applies the Instant photo effect. - **photoEffectMono()**: Applies the Mono photo effect. - **photoEffectNoir()**: Applies the Noir photo effect. - **photoEffectProcess()**: Applies the Process photo effect. - **photoEffectTonal()**: Applies the Tonal photo effect. - **photoEffectTransfer()**: Applies the Transfer photo effect. - **pinchDistortion()**: Applies pinch distortion. - **pinLightBlendMode()**: Applies the Pin Light blend mode. - **pixellate()**: Applies a pixellate effect. - **pointillize()**: Applies a pointillize effect. - **points**: Accesses the points of the path. - **printImage**: Prints the image. ``` -------------------------------- ### DrawBot: Canvas Setup and Basic Shapes Source: https://www.drawbot.com/content/quickReference Demonstrates how to set the canvas size and draw fundamental shapes like rectangles and ovals using DrawBot in Python. It also shows how to print canvas dimensions. ```python # DrawBot reference # set a size for the canvas size(500, 500) # using the functions width, height and pageCount print("width:", width()) print("height:", height()) print("pageCount:", pageCount()) # simple shapes # draw rect x, y, width, height rect(10, 10, 100, 100) # draw oval x, y, width, height oval(10, 120, 100, 100) ovel(120, 120, 100, 100) # draw polygon polygon((10, 250), (100, 250), (100, 400), (50, 300), close=False) ``` -------------------------------- ### Path Construction Methods Source: https://www.drawbot.com/content/shapes/bezierPath Methods for starting, ending, and adding segments to a Bezier path. ```APIDOC ## Path Construction ### `drawPath(path)` Draws the path again. ### `contourClass` Alias for `BezierContour`. ### `moveTo(_point_)` Move to a point (x, y). ### `lineTo(_point_)` Draw a line to a point (x, y). ### `curveTo(* points)` Draw a cubic Bezier curve with an arbitrary number of control points. The last point is on-curve, others are off-curve control points. ### `qCurveTo(* points)` Draw a series of quadratic curve segments. The last point is on-curve, others are off-curve control points. ### `closePath()` Close the current path. ### `beginPath(identifier=None)` Begin a new subpath, using the path as a point pen. ### `addPoint(point, segmentType=None, smooth=False, name=None, identifier=None, **kwargs)` Add a point to the current subpath using the path as a point pen. `beginPath` must be called first. ### `endPath()` End the current subpath. If used as a segment pen, finishes an open contour. If used as a point pen, processes added points. ``` -------------------------------- ### DrawBot Shapes - Rectangle Example Source: https://www.drawbot.com/content/courseware Provides a basic example of drawing a rectangle using DrawBot. This snippet is intended as an introduction to the drawing primitives available in DrawBot, with further details available on the Drawing Primitives pages. ```python # draw a rectangle ``` -------------------------------- ### DrawBot: Creating and Drawing Paths with drawPath Source: https://www.drawbot.com/content/shapes/drawingPath Illustrates how to create a new path, define its points using `moveTo`, `lineTo`, and `curveTo`, close the path, and then render it using `drawPath`. This is a fundamental example for path construction. ```python # create a new empty path newPath() # set the first oncurve point moveTo((100, 100)) # line to from the previous point to a new point lineTo((100, 900)) lineTo((900, 900)) # curve to a point with two given handles curveTo((900, 500), (500, 100), (100, 100)) # close the path closePath() # draw the path drawPath() ``` -------------------------------- ### ImageObject Methods (R) Source: https://www.drawbot.com/genindex Lists ImageObject methods starting with 'R', including radial gradients and various transformations. ```APIDOC ## ImageObject Methods (R) ### Description Provides access to ImageObject manipulation methods starting with the letter 'R'. ### Methods - **radialGradient()**: Generates a radial gradient. - **randomGenerator()**: Creates a random number generator. - **removeOverlap()**: Removes overlapping path segments. - **restore**: Restores the drawing state. - **reverse()**: Reverses the order of path points. - **rippleTransition()**: Applies a ripple transition. - **rotate()**: Rotates the image or path. - **roundedRectangleGenerator()**: Generates a rounded rectangle. - **roundedRectangleStrokeGenerator()**: Generates a rounded rectangle stroke. - **rowAverage()**: Calculates the average of pixel values per row. ``` -------------------------------- ### TextBox Baselines Source: https://www.drawbot.com/content/text/drawingText Calculates the starting coordinates for each line of text within a given bounding box. ```APIDOC ## textBoxBaselines ### Description Returns a list of x, y coordinates indicating the start of each line for a given text in a given box. A box could be a (x, y, w, h) or a bezierPath object. Optionally an alignment can be set. Possible align values are: “left”, “center”, “right” and “justified”. ### Method N/A (Function) ### Endpoint N/A (Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python # Example usage (conceptual, requires DrawBot environment) # box = (0, 0, 100, 50) # baselines = textBoxBaselines("Line 1\nLine 2", box, align="left") ``` ### Response #### Success Response (200) - **baselines** (list of dict) - A list where each item contains 'x' and 'y' coordinates for the start of a text line. #### Response Example ```json [ {"x": 10.0, "y": 15.0}, {"x": 10.0, "y": 30.0} ] ``` ``` -------------------------------- ### DrawBot: Drawing Paths with arcTo Example Source: https://www.drawbot.com/content/shapes/drawingPath Demonstrates the use of `arcTo` to draw a path segment with a specified radius between two points, using BezierPath objects. It visualizes the points, handles, and the resulting path. ```python pt0 = 74, 48 pt1 = 238, 182 pt2 = 46, 252 radius = 60 def drawPt(pos, r=5): x, y = pos oval(x-r, y-r, r*2, r*2) size(300, 300) fill(None) path = BezierPath() path.moveTo(pt0) path.arcTo(pt1, pt2, radius) stroke(0, 1, 1) polygon(pt0, pt1, pt2) for pt in [pt0, pt1, pt2]: drawPt(pt) stroke(0, 0, 1) drawPath(path) stroke(1, 0, 1) for pt in path.onCurvePoints: drawPt(pt, r=3) for pt in path.offCurvePoints: drawPt(pt, r=2) ``` -------------------------------- ### ImageObject Methods (N) Source: https://www.drawbot.com/genindex Lists ImageObject methods starting with 'N', including ninePart variations and noise reduction. ```APIDOC ## ImageObject Methods (N) ### Description Provides access to ImageObject manipulation methods starting with the letter 'N'. ### Methods - **ninePartStretched()**: Applies a nine-part stretched transformation. - **ninePartTiled()**: Applies a nine-part tiled transformation. - **noiseReduction()**: Reduces noise in the image. - **numberOfPages**: Gets the number of pages in the document. ``` -------------------------------- ### Python Loops and Indentation in DrawBot Source: https://www.drawbot.com/content/courseware Demonstrates various ways to use loops in Python, including 'for' loops, nested loops, and iterating over ranges. It also illustrates Python's reliance on indentation for code blocks and provides examples of manual and shortcut indentation. ```python print("hello") # also: use the tab key to manually # indent. There are shortcuts to indent # or dedent blocks of code: cmd-[ print("loop over some numbers:") for item in range(10): print(item) print("loop over some numbers, doing 'math':") for i in range(10): print(i, i * 0.5) print("nested loops:") for x in range(1, 5): # outer loop print("---") for y in range(x, x + 5): # inner loop print(x, y, x * y) print("three loops:") for x in range(2): for y in range(2): for z in range(2): print(x, y, z) print("three loops with a counter:") count = 1 for x in range(2): for y in range(2): for z in range(2): print(x, y, z, count) count = count + 1 # alternate spelling: #count += 1 ``` -------------------------------- ### Integrate Vanilla UI Elements with DrawBot Variables Source: https://www.drawbot.com/content/variables This example showcases integrating DrawBot's `Variable()` function with various UI elements provided by the vanilla framework. It demonstrates setting up variables with different control types such as `PopUpButton`, `EditText`, `Slider`, `CheckBox`, `ColorWell`, and `RadioGroup`. The script then prints the current values of these variables, illustrating how they can be populated and accessed within the DrawBot environment. ```python # Variable == vanilla power in DrawBot from AppKit import NSColor # create a color _color = NSColor.colorWithCalibratedRed_green_blue_alpha_(0, .5, 1, .8) # setup variables using different vanilla ui elements. Variable([ dict(name="aList", ui="PopUpButton", args=dict(items=['a', 'b', 'c', 'd'])), dict(name="aText", ui="EditText", args=dict(text='hello world')), dict(name="aSlider", ui="Slider", args=dict(value=100, minValue=50, maxValue=300)), dict(name="aCheckBox", ui="CheckBox", args=dict(value=True)), dict(name="aColorWell", ui="ColorWell", args=dict(color=_color)), dict(name="aRadioGroup", ui="RadioGroup", args=dict(titles=['I', 'II', 'III'], isVertical=False)), ], globals()) print(aList) print(aText) print(aSlider) print(aCheckBox) print(aColorWell) print(aRadioGroup) ``` -------------------------------- ### Python Lists and Loops in DrawBot Source: https://www.drawbot.com/content/courseware Introduces Python lists as ordered collections of items, which can include various data types. The script demonstrates how to create lists, append items, access elements by index (positive and negative), and create nested lists. It also shows how strings are sequences and how to extract 'slices' from lists. Finally, it illustrates the use of 'for' loops to iterate over list items and includes examples of the `range()` function. ```python # let's introduce 'lists' (or 'arrays' as # they are called in some other languages) alist = [1, -2, "asdsd", 4, 50] print(alist) alist.append(1234) print(alist) # fetching an item from the list: print(alist[0]) # the first item print(alist[1]) # the second # negative numbers start from the end: print(alist[-1]) # the last item print(alist[-2]) # the one before last print("nested lists:") print([1, 2, 3, ["a", "b", "c"]]) print([1, 2, 3, ["a", ["deeper"]]]) # assigning a list to another name does # not make a copy: you just create another # reference to the same object anotherlist = alist anotherlist.append(-9999) print(anotherlist) print(alist) acopy = list(alist) acopy.append(9999) print(acopy) print(alist) # strings are also sequences: astring = "abcdefg" print(astring[2]) print(astring[-1]) # from the end print("getting 'slices' from a list:") print(alist) print(alist[2:5]) print("there's a nice builtin function that") print("creates a list of numbers:") print(range(10)) # from 0 to 10 (not incl. 10!) print(range(5, 10)) # from 5 to 10 (not incl. 10!) print(range(1, 19, 3)) # from 1 to 19 in steps of 3 print("let's loop over this list:") print(alist) for item in alist: # this is the body of the "for" loop print(item) # more lines following can follow # you need to indent consistently, # this would not work: ``` -------------------------------- ### Set Line Dash Pattern in DrawBot Source: https://www.drawbot.com/content/shapes/pathProperties The `lineDash()` function in DrawBot enables the creation of dashed lines. It accepts a sequence of lengths for dashes and gaps, and an optional offset for the starting dash. This example shows how to apply different dash patterns and offsets. ```python # set stroke color to black stroke(0) # set a strok width strokeWidth(50) # translate the canvas translate(150, 50) # set a line dash lineDash(2, 2) # draw a line line((0, 200), (0, 800)) # translate the canvas translate(200, 0) # set a line dash lineDash(2, 10, 5, 5) # draw a line line((0, 200), (0, 800)) # translate the canvas translate(200, 0) # set a line dash and offset lineDash(2, 10, 5, 5, offset=2) # draw a line line((0, 200), (0, 800)) # translate the canvase translate(200, 0) # reset the line dash lineDash(None) # draw a line line((0, 200), (0, 800)) ``` -------------------------------- ### DrawBot: Image Placement Source: https://www.drawbot.com/content/quickReference Shows how to place an image onto the canvas at specified coordinates and with a given alpha transparency using DrawBot in Python. It also demonstrates advancing to a new page. ```python newPage() # image: path, (x, y), alpha image("https://github.com/typemytype/drawbot/raw/master/docs/content/assets/drawBot.jpg", (10, 10), .5) ``` -------------------------------- ### Guided Filter Source: https://www.drawbot.com/content/image/imageObject Upsamples a small image to the size of a guide image, using the guide's content to preserve detail. Parameters include the guide image, radius, and epsilon. ```APIDOC ## GUIDEDFILTER /websites/drawbot ### Description Upsamples a small image to the size of the guide image using the content of the guide to preserve detail. ### Method POST ### Endpoint /websites/drawbot/guidedFilter ### Parameters #### Query Parameters - **guideImage** (Image object) - Required - A larger image to use as a guide. - **radius** (float) - Optional - The distance from the center of the effect. Defaults to 1.0. - **epsilon** (float) - Optional - A small value to prevent division by zero. Defaults to 0.0001. ### Request Example (No request body specified for this filter) ### Response #### Success Response (200) - **image** (Image) - The upsampled image. #### Response Example (No response body example provided) ``` -------------------------------- ### CMYK Radial Gradient API Source: https://www.drawbot.com/content/color/cmykFill A cmyk radial gradient fill with specified start and end points, colors, optional locations, start radius, and end radius. ```APIDOC ## cmykRadialGradient() ### Description A cmyk radial gradient fill with: * startPoint as (x, y) * endPoint as (x, y) * colors as a list of colors, described similarly as cmykFill * locations of each color as a list of floats. (optionally) * startRadius radius around the startPoint in degrees (optionally) * endRadius radius around the endPoint in degrees (optionally) Setting a gradient will ignore the fill. ### Method `cmykRadialGradient(_startPoint =None_, _endPoint =None_, _colors =None_, _locations =None_, _startRadius =0_, _endRadius =100_)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python # set a gradient as the fill color cmykRadialGradient( (300, 300), # startPoint (600, 600), # endPoint [(1, 0, 0, 1), (0, 0, 1, 0), (0, 1, 0, .2)], # colors [0, .2, 1], # locations 0, # startRadius 500 # endRadius ) # draw a rectangle rect(10, 10, 980, 980) ``` ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### DrawBot: Path Creation and Drawing Source: https://www.drawbot.com/content/quickReference Illustrates the creation and drawing of custom paths using DrawBot's Bezier path functions in Python. This includes moving to points, drawing lines, curves, and closing the path. ```python # create path newPath() # move to point moveTo((300, 100)) lineTo((400, 100)) # first control point (x1, y1) # second control point (x2, y2) # end point (x3, y3) curveTo((450, 150), (450, 250), (400, 300)) lineTo((300, 300)) # close the path closePath() # draw the path drawPath() ``` -------------------------------- ### DrawBot: Clipping Paths and Saving Output Source: https://www.drawbot.com/content/quickReference Demonstrates how to use clipping paths to mask drawing areas and how to save the output in various formats like PDF, PNG, SVG, and MP4 using DrawBot in Python. It includes saving with a Bezier path clip. ```python newPage() save() path = BezierPath() path.oval(20, 20, 300, 100) clipPath(path) fill(1, 0, 0, .3) rect(10, 10, 100, 100) fontSize(30) text("Hello World", (50, 80)) restore() ovel(200, 20, 50, 50) saveImage(u"~/Desktop/drawBotTest.pdf") saveImage(u"~/Desktop/drawBotTest.png") saveImage(u"~/Desktop/drawBotTest.svg") saveImage(u"~/Desktop/drawBotTest.mp4") print("Done") ``` -------------------------------- ### DrawBot: Color Fills and Strokes Source: https://www.drawbot.com/content/quickReference Explains how to apply different fill and stroke colors, including grayscale, RGB, and alpha transparency, using DrawBot in Python. It covers setting fill to None and stroke width. ```python newPage() print("pageCount:", pageCount()) # colors # fill(r, g, b) # fill(r, g, b, alpha) # fill(grayvalue) # fill(grayvalue, alpha) # fill(None) fill(.5) rect(10, 10, 100, 100) fill(1, 0, 0) rect(10, 120, 100, 100) fill(0, 1, 0, .5) ovel(50, 50, 100, 100) fill(None) # stroke(r, g, b) # stroke(r, g, b, alpha) # stroke(grayvalue) # stroke(grayvalue, alpha) # stroke(None) strokeWidth(8) stroke(.8) rect(200, 10, 100, 100) stroke(.1, .1, .8) rect(200, 120, 100, 100) strokeWidth(20) stroke(1, 0, 1, .5) ovel(250, 50, 100, 100) ``` -------------------------------- ### DrawBot: Set Radial Gradient Fill Source: https://www.drawbot.com/content/color/fill Configures a radial gradient fill for shapes, specifying start and end points, colors, and optionally, color stop locations, start radius, and end radius. This setting bypasses the standard fill color. ```python # set a gradient as the fill color radialGradient( (300, 300), # startPoint (600, 600), # endPoint [(1, 0, 0), (0, 0, 1), (0, 1, 0)], # colors [0, .2, 1], # locations 0, # startRadius 500 # endRadius ) # draw a rectangle rect(10, 10, 980, 980) ``` -------------------------------- ### Install and Use Custom Font in DrawBot Source: https://www.drawbot.com/content/text/drawingText Demonstrates how to install a custom font for the current DrawBot process using its file path, set it as the active font, draw text with it, and then uninstall it. Note that fonts are only available for the current script execution and are automatically removed upon completion. ```python # set the path to a font file path = "path/to/font/file.otf" # install the font fontName = installFont(path) # set the font font(fontName, 200) # draw some text text("Hello World", (10, 10)) # uninstall font uninstallFont(path) ``` -------------------------------- ### Create and Draw a Bezier Path in Python Source: https://www.drawbot.com/content/shapes/bezierPath Demonstrates how to create a BezierPath object, define its shape using moveTo, lineTo, and closePath, and then draw it multiple times with varying fill colors and translations. It also shows how to add text to a path and access its point data. ```python from drawBot import BezierPath, drawPath, translate, fill, random # create a bezier path path = BezierPath() # move to a point path.moveTo((100, 100)) # line to a point path.lineTo((100, 200)) path.lineTo((200, 200)) # close the path path.closePath() # loop over a range of 10 for i in range(10): # set a random color with alpha value of .3 fill(random(), random(), random(), .3) # in each loop draw the path drawPath(path) # translate the canvas translate(50, 50) path.text("Hello world", font="Helvetica", fontSize=30, offset=(210, 210)) print("All Points:") print(path.points) print("On Curve Points:") print(path.onCurvePoints) print("Off Curve Points:") print(path.offCurvePoints) # print out all points from all segments in all contours for contour in path.contours: for segment in contour: for x, y in segment: print((x, y)) print(["contour is closed", "contour is open"][contour.open]) # translate the path path.translate(0, -100) # draw the path again drawPath(path) # translate the path path.translate(-300, 0) path.scale(2) ``` -------------------------------- ### DrawBot: RGB Colors and Gradients Source: https://www.drawbot.com/content/quickReference Illustrates the use of RGB color modes and gradients in DrawBot for Python, including linear and radial gradients, and shadows. It shows how to apply these to shapes. ```python newPage() print("pageCount:", pageCount()) fill(1, 0, 1) linearGradient((10, 10), (200, 20), ([1, 1, 0], [0, 1, 1])) rect(10, 10, 200, 200) radialGradient((50, 410), (50, 410), ([1, 0, 1], [1, 1, 0], [0, 1, 1]), startRadius=0, endRadius=300) rect(10, 310, 100, 150) shadow((10, 10), 20, (1, 0, 0)) ovel(130, 310, 300, 150) ``` -------------------------------- ### Uninstall Font Source: https://www.drawbot.com/content/text/drawingText Uninstalls a font that was previously installed using its file path. ```APIDOC ## uninstallFont ### Description Uninstall a font with a given path. This function has been deprecated: please use the font path directly in all places that accept a font name. ### Method N/A (Function) ### Endpoint N/A (Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python # Example usage (conceptual, requires DrawBot environment) # path = "path/to/font/file.otf" # uninstallFont(path) ``` ### Response #### Success Response (200) None (Operation is typically void or returns a success status). #### Response Example ```json { "status": "success" } ``` ``` -------------------------------- ### BezierPath Method (qCurveTo) Source: https://www.drawbot.com/genindex Documentation for the qCurveTo method of the BezierPath object within the drawBot module. ```APIDOC ## BezierPath qCurveTo Method ### Description Adds a quadratic Bézier curve segment to the path. ### Method - **qCurveTo()**: Adds a quadratic Bézier curve. ``` -------------------------------- ### ImageObject Methods (M) Source: https://www.drawbot.com/genindex This section lists various methods available for ImageObject manipulation starting with 'M', such as maskedVariableBlur, maskToAlpha, and multiplyBlendMode. ```APIDOC ## ImageObject Methods (M) ### Description Provides access to ImageObject manipulation methods starting with the letter 'M'. ### Methods - **maskedVariableBlur()**: Applies a masked variable blur effect. - **maskToAlpha()**: Converts a mask to an alpha channel. - **maximumComponent()**: Gets the maximum component of an image. - **maximumCompositing()**: Applies maximum compositing. - **meshGenerator()**: Generates a mesh for the image. - **minimumComponent()**: Gets the minimum component of an image. - **minimumCompositing()**: Applies minimum compositing. - **mix()**: Mixes the image with another. - **modTransition()**: Applies a modulation transition. ``` -------------------------------- ### BezierPath Methods Source: https://www.drawbot.com/genindex This section covers methods related to creating and manipulating Bezier paths. ```APIDOC ## BezierPath Methods ### Description Provides methods for creating and modifying Bezier paths, including drawing, expanding strokes, and retrieving path information. ### Methods - **endPath()**: Finalizes the current path. - **expandStroke()**: Expands the stroke of a path into a fill. - **getNSBezierPath()**: Retrieves the underlying NSBezierPath object. - **intersection()**: Calculates the intersection of two paths. - **intersectionPoints()**: Finds the intersection points between two paths. - **line()**: Draws a straight line segment. - **lineTo()**: Adds a line segment to the current path. - **listColorSpaces()**: Lists available color spaces. ``` -------------------------------- ### Circle Splash Distortion Source: https://www.drawbot.com/content/image/imageObject Distorts pixels starting from the circumference of a circle outwards. Parameters include center and radius. ```APIDOC ## POST /websites/drawbot/circleSplashDistortion ### Description Distorts the pixels starting at the circumference of a circle and emanating outward. ### Method POST ### Endpoint /websites/drawbot/circleSplashDistortion ### Parameters #### Query Parameters - **center** (tuple[float, float]) - Optional - The center of the effect as x and y pixel coordinates. Defaults to (150.0, 150.0). - **radius** (float) - Optional - The radius determines how many pixels are used to create the distortion. The larger the radius, the wider the extent of the distortion. Defaults to 150.0. ### Request Example ```json { "image_data": "base64_encoded_image" } ``` ### Response #### Success Response (200) - **image_data** (string) - Base64 encoded image data after applying the circle splash distortion. #### Response Example ```json { "image_data": "base64_encoded_distorted_image" } ``` ``` -------------------------------- ### CMYK Linear Gradient API Source: https://www.drawbot.com/content/color/cmykFill A cmyk linear gradient fill with specified start and end points, colors, and optional locations. ```APIDOC ## cmykLinearGradient() ### Description A cmyk linear gradient fill with: * startPoint as (x, y) * endPoint as (x, y) * colors as a list of colors, tuples of floating point values (0 → 1) * locations of each color as a list of floats. (optionally) Setting a gradient will ignore the fill. ### Method `cmykLinearGradient(_startPoint =None_, _endPoint =None_, _colors =None_, _locations =None_)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python # set a gradient as the fill color cmykLinearGradient( (100, 100), # startPoint (800, 800), # endPoint [(1, 0, 0, 0), (0, 0, 1, 0), (0, 1, 0, 0)], # colors [0, .2, 1] # locations ) # draw a rectangle rect(10, 10, 980, 980) ``` ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### Image Object Information Retrieval (Python) Source: https://www.drawbot.com/content/image/imageObject Retrieves metadata or state information from an Image object. Methods include getting size, offset, and clearing filters. ```Python imageObject.size() imageObject.offset() imageObject.clearFilters() ``` -------------------------------- ### DrawBot: Canvas Transformations (Save, Scale, Rotate, Skew) Source: https://www.drawbot.com/content/quickReference Demonstrates how to apply transformations like scaling, rotation, and skewing to the canvas using DrawBot's save, restore, scale, rotate, and skew functions in Python. Transformations are applied to shapes drawn afterwards. ```python newPage() # canvas transformations print("pageCount:", pageCount()) fill(None) stroke(0) strokeWidth(3) save() rect(10, 10, 100, 100) scale(2) rect(10, 10, 100, 100) restore() save() rotate(30) rect(10, 10, 100, 100) restore() save() skew(30) rect(10, 10, 100, 100) restore() ``` -------------------------------- ### Image Object Management (Python) Source: https://www.drawbot.com/content/image/imageObject Handles the lifecycle and state of an Image object, including opening, copying, and focus management. Requires a file path for opening and image objects for focus. ```Python imageObject.open(_path_) imageObject.copy() imageObject.lockFocus() imageObject.unlockFocus() ``` -------------------------------- ### Glass Lozenge Filter Source: https://www.drawbot.com/content/image/imageObject Creates a lozenge-shaped lens that distorts the portion of the image it covers. Parameters include the start and end points of the lozenge, its radius, and the refraction index. ```APIDOC ## GLASSLOZENGE /websites/drawbot ### Description Creates a lozenge-shaped lens and distorts the portion of the image over which the lens is placed. ### Method POST ### Endpoint /websites/drawbot/glassLozenge ### Parameters #### Query Parameters - **point0** (tuple) - Optional - A tuple (x, y) defining the center of the circle at one end of the lozenge. Defaults to (150.0, 150.0). - **point1** (tuple) - Optional - A tuple (x, y) defining the center of the circle at the other end of the lozenge. Defaults to (350.0, 150.0). - **radius** (float) - Optional - The radius of the lozenge. The larger the radius, the wider the extent of the distortion. Defaults to 100.0. - **refraction** (float) - Optional - The refraction of the glass. Defaults to 1.7. ### Request Example (No request body specified for this filter) ### Response #### Success Response (200) - **image** (Image) - The image with the lozenge distortion applied. #### Response Example (No response body example provided) ``` -------------------------------- ### DrawBot: Get Formatted String Size Source: https://www.drawbot.com/content/text/formattedString Retrieves the calculated bounding box size of the formatted string. This is useful for layout calculations, determining space requirements before drawing, or for responsive design. ```python from drawBot import * # Example usage: t = FormattedString() t.text('Hello, DrawBot!') textSize = t.size() print(f'Text size: {textSize}') # Expected output might be a tuple like (width, height) ``` -------------------------------- ### Set Character Tracking in DrawBot Source: https://www.drawbot.com/content/text/textProperties Control the spacing between characters in a text string. A positive value increases spacing, while None resets it to default. This example demonstrates increasing and then disabling tracking. ```python size(1000, 350) # set tracking tracking(100) # set font size fontSize(100) # draw some text text("hello", (100, 200)) # disable tracking tracking(None) # draw some text text("world", (100, 100)) ``` -------------------------------- ### Enable Hyphenation for Text in DrawBot Source: https://www.drawbot.com/content/text/textProperties Control hyphenation for text, enabling or disabling it with a boolean value. This example shows enabling hyphenation and drawing a large block of text within a defined box. ```python txt = '''Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.''' # enable hyphenation hyphenation(True) # set font size fontSize(50) # draw text in a box textBox(txt, (100, 100, 800, 800)) ``` -------------------------------- ### Apply Underline to Text in DrawBot Source: https://www.drawbot.com/content/text/textProperties Apply an underline style to text. Supported values are 'single', 'thick', 'double', or None. This example demonstrates setting underline and font size before drawing text. ```python underline("single") fontSize(140) text("hello underline", (50, 50)) ``` -------------------------------- ### Python Functions Definition and Calling in DrawBot Source: https://www.drawbot.com/content/courseware Explains how to define and call functions in Python. It covers defining functions with and without arguments, passing arguments, and returning values from functions. It also touches upon global variables and local scope. ```python # defining a function: def myfunction(): print("hello!") # calling the function: myfunction() # a common error # not calling the function: myfunction # note missing () # defining a function that takes an # 'argument' (or 'parameter') def mysecondfunction(x, y): print("hello!") print(x, y) # calling the function with 2 arguments mysecondfunction(123, 456) def add2numbers(x, y): # you can see 'global' vars print(aglobalvariable) result = x + y return result aglobalvariable = "hi!" thereturnedvalue = add2numbers(1, 2) print(thereturnedvalue) # 'result' was a local name inside # add2number, so it is not visible at the # top level. So the next line would cause # an error: #print(result) def anotherfunc(x, y): # calling add2numbers function: return add2numbers(x, y) print(anotherfunc(1, 2)) ``` -------------------------------- ### Manage and Draw on Multiple Pages with DrawBot Source: https://www.drawbot.com/content/canvas/pages Demonstrates advanced page management in DrawBot. It shows creating multiple pages with different sizes and colors, retrieving all pages using pages(), and then selectively drawing on specific pages using a 'with' statement. This allows for fine-grained control over multi-page document creation. ```python # set a size size(200, 200) # draw a rectangle rect(10, 10, 100, 100) # create a new page newPage(200, 300) # set a color fill(1, 0, 1) # draw a rectangle rect(10, 10, 100, 100) # create a new page newPage(200, 200) # set a color fill(0, 1, 0) # draw a rectangle rect(10, 10, 100, 100) # get all pages allPages = pages() # count how many pages are available print(len(allPages)) # use the `with` statement # to set a page as current context with allPages[1]: # draw into the selected page fontSize(30) text("Hello World", (10, 150)) # loop over allpages for page in allPages: # set the page as current context with page: # draw an oval in each of them oval(110, 10, 30, 30) ``` -------------------------------- ### Get Image Size in DrawBot Source: https://www.drawbot.com/content/image/imageProperties Retrieves the width and height of an image. Supports PDF, JPG, PNG, TIFF, and GIF file formats, as well as NSImage objects. Returns a tuple of (width, height). ```python print(imageSize("https://raw.githubusercontent.com/typemytype/drawbot/master/tests/data/drawBot.jpg")) ```