The DrawShield API

From DrawShield Documentation
Revision as of 22:44, 5 October 2023 by Karlw (talk | contribs) (Created page with "The Shield Drawing function of DrawShield can be invoked in 3 ways: 1. From the command line (no options are processed and the output is fixed as PNG). This mode is largely for debugging but might also be useful for bulk generation of PNG images. 1. Via an HTTP POST request - this is the recommended method as it gives the greatest flexibility and range of options (described below). This the method used by the drawshield.net website "create" page. 1. Via an HTTP GET re...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The Shield Drawing function of DrawShield can be invoked in 3 ways:

1. From the command line (no options are processed and the output is fixed as PNG). This mode is largely for debugging but might also be useful for bulk generation of PNG images.

1. Via an HTTP POST request - this is the recommended method as it gives the greatest flexibility and range of options (described below). This the method used by the drawshield.net website "create" page.

1. Via an HTTP GET request - this is also useful and quite flexible, the only option not available is that it is not possible to provide the blazon in an uploaded file.

  1. DrawShield from the command line

This is a very simple process, all of the arguments will be concatenated into a single string, separated by spaces and this will be treated as the blazon. A file named shield.png will be created which will be 500 pixels wide, using the DrawShield colour scheme, the heater shield shape and the shiny effect.

The program should be run from the top level directory containing the drawshield code. An example command line would be:

`php drawshield.php azure a bend or`

If there are no arguments the program will instead look for a file in the same folder named ‘debug.inc’. If this exists it will be “included” and hence should consist of PHP code. Most usefully this code should set the various values of the $options array, for example:

`$options[“blazon”] = ”azure a bend or“;`

You can also set other options as required. This is the suggested method for using a PHP debugger.

  1. Options for GET and POST

If the drawshield code is installed on a PHP enabled web-server it can be invoked either by a GET or a POST request. An equivalent GET request to the example above would be:

`http://drawshield.net/include/drawshield.php?blazon=azure%20a%20bend%20or`

If you install the drawshield code on your own server then obviously the URL and the initial path may be different.

Except where noted below, the GET and POST methods to drawshield accept the same set of arguments. All argument names and values *must* be lowercase, except for the blazon, which may in mixed case and contain accented characters.

      1. blazon

This is the only mandatory argument, although it can be blank, in which case an empty shield is constructed and returned. The value *must* be entity encoded.

As noted above, mixed case and accented characters are supported (although this is not necessary, for parsing purposes the program will lowercase all input and "collapse" accented characters to their unaccented versions). Case and accents are preserved in strings, for example `vert the word "Olé" argent` will display as shown.

      1. blazonfile

This argument is only available with the POST method. If a form includes multi-part data with the name "blazonfile", a filename that ends in ".txt" and is less than 100,000 characters long then the contents of that multi-part data will be used as the input blazon. Note that the existence of blazonfile will *take precedence* over a blazon given in the "blazon" argument.

      1. outputformat

This argument determines the output format of the drawn shield, allowable values are:

  • svg - SVG vector graphic format, XML data rendered as an image by your browser (default)
  • jpg - JPEG image
  • png - PNG image with a transparent background
  • json - This format combines several types of data in a JSON wrapper, see the section below

(Note that if the argument "asfile" is present then this argument is *ignored* - the argument "saveformat" is used instead)

      1. size

This argument is slightly mis-named in that it is actually the width of the resulting image. It will be coerced to be at least 100 but has no upper limit. The default value is 500. It represents the width in pixels of the rendered image. The height of the image will usually be 1.2 times the width but some shapes have slightly different values.

      1. shape

This option sets the outline shape of the shield, allowable values are:

| Value | Shape | |-------|:-----:| | heater (default)|![Example Shape](http://drawshield.net/create/img/heater.png)%7C | french|![Example Shape](http://drawshield.net/create/img/french.png) | | oval|![Example Shape](http://drawshield.net/create/img/oval.png) | | lozenge|![Example Shape](http://drawshield.net/create/img/lozenge.png) | | square|![Example Shape](http://drawshield.net/create/img/square.png) | | italian|![Example Shape](http://drawshield.net/create/img/italian.png) | | swiss|![Example Shape](http://drawshield.net/create/img/swiss.png) | | english|![Example Shape](http://drawshield.net/create/img/english.png) | | german|![Example Shape](http://drawshield.net/create/img/german.png) | | polish|![Example Shape](http://drawshield.net/create/img/polish.png) | | spanish|![Example Shape](http://drawshield.net/create/img/spanish.png) | | flag|![Example Shape](http://drawshield.net/create/img/flag.png) |

      1. ar

This option only makes a difference if the *flag* shape is chosen - it sets the proportions (aspect ratio) of the flag and can be specified either as a ratio (e.g. 9:10) or a decimal value (e.g. 0.9). The value is automatically constrained to sensible limits.

      1. palette

This option sets the choice of colours to be used in displaying the shield. (There is no defined meaning of heraldic colours other than, for example, "gules" is to be represented as something resembling "red"). Various authorities have developed their own colour choices and drawshield supports the following option values:

| Value | Example Palette | |-------|:-----:| | drawshield (default)|![Example Palette](http://drawshield.net/create/img/drawshield.png)%7C | wikipedia|![Example Palette](http://drawshield.net/create/img/wikipedia.png) | | emoji|![Example Palette](http://drawshield.net/create/img/emoji.png) | | wappenwiki|![Example Palette](http://drawshield.net/create/img/wappenwiki.png) | | outline|![Example Palette](http://drawshield.net/create/img/outline.png) | | bajuvarian|(N/A) |

You can define your own colour palette, following the instructions on [this page.](https://github.com/karlwilcox/Drawshield-Code/wiki/Colour-Palettes).

      1. Additional Colour Names

The palette above refers to the colour values for the standard heraldic named colours. In addition to these it is also possible use sets of other colours, that are NOT heraldic but are useful in specific situations like flags, pauldrons and tartans. These additional colour sets can be enabled by the following options:

  • webcols=yes - allow any of the named web colours to be used
  • whcols=yes - allow any of the named Warhammer 40,000 colours from the Citadel Minatures paint range to be used
  • tartancols=yes - allow any of the standard Tartan colour names to be used

For more details on these colours see [the Colour Reference section in the visual catalog](https://drawshield.net/catalog/colours/index.html)

      1. effect

DrawShield supports some simple effects to give your shield the appearance of being constructed in a particular material. These effects are achieved by applying an SVG filter, most of which are based on those built in to Inkscape whose authors I would like to thank. All the filters except plain (which actually means "no filter") affect the colour values set by the palette. To get just the pure colours from your chosen palette select the "plain" value for effect. The available values are:

| Value | Example Effect | Explanation | |-------|:-----:|------| | shiny|![Example Palette](http://drawshield.net/create/img/shiny.png)%7CSupposed to look like a metallic surface with a highlight in the top left and coloured shadows to lower right| | plain (default)|![Example Palette](http://drawshield.net/create/img/plain.png) |No filters, show the pure colours from the palette.| | stonework|![Example Palette](http://drawshield.net/create/img/stonework.png) |Supposed to look like a slightly roughened stone surface that has been overpainted with the shield.| | plaster|![Example Palette](http://drawshield.net/create/img/plaster.png) |Supposed to look like the design has been embossed into wet plaster but isn't really very good!| | vellum|![Example Palette](http://drawshield.net/create/img/vellum.png) |Supposed to look like the design has been inked onto rough vellum (animal skin). I quite like this one!|

Suggestions for new filters (ideally in the form of SVG code!) are very welcome.

      1. asfile

If this option is present then instead of returning the image the program will force the download of the image as a file, called "shield.svg", "shield.png" or "shield.jpg" depending on the setting of the "saveformat" option.

      1. saveformat

This option selects the file format for the "asfile" option, it takes the same values as "outputformat" above.

      1. printable (Deprecated)

This option used to turn off the text shown to the bottom left of the shield when saving as a file. This happens automatically now so the option is no longer required.

      1. stage (Deprecated)

This used to provide debugging information but there is now more complete data available in the json format.