Difference between revisions of "The DrawShield API"

From DrawShield Documentation
m
m
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
The Shield Drawing function of DrawShield can be invoked in 3 ways:
= A Plea to API users =


# 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.
''DrawShield is hosted on a very small AWS LightSail, with a fixed amount of resource, it does NOT scale under load. Please rate-limit your use of the remote API to no more than a handful of requests per second. Any more is likely to overload the server possibly causing it to fail.''
# 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.
# 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.
 
= 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:
 
<code>php drawshield.php azure a bend or</code>
 
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:
 
<code>$options[“blazon”] = ”azure a bend or“;</code>
 
You can also set other options as required. This is the suggested method for using a PHP debugger.


= Options for GET and POST =
= 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:
If the drawshield code is installed on a PHP enabled web-server (such as drawshield.net) it can be invoked either by a GET or a POST request. An example GET request would be:


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


If you install the drawshield code on your own server then obviously the URL and the initial path may be different.
If you install the drawshield code on your own server then obviously the URL and the initial path may be different. Note that, although this method simple it is not the most flexible as it cannot be used to generate a blazon from a file and there is an upper limit to the length of the URL that varies from server to server.
 
The HTTP POST request 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 &quot;create&quot; page.


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.
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.
Unrecognised arguments are silently ignored (this includes miss-spellings of the accepted arguments, so check your request carefully).


=== blazon ===
=== blazon ===
Line 44: Line 32:


* svg - SVG vector graphic format, XML data rendered as an image by your browser (default)
* svg - SVG vector graphic format, XML data rendered as an image by your browser (default)
* jpg - JPEG image
* jpg (or jpeg) - JPEG image
* webp - Google's WebP Image Format
* png - PNG image with a transparent background
* png - PNG image with a transparent background
* json - This format combines several types of data in a JSON wrapper, see the section below
* json - This format combines several types of data in a JSON wrapper, see [[The JSON Output Format]]


(Note that if the argument &quot;asfile&quot; is present then this argument is ''ignored'' - the argument &quot;saveformat&quot; is used instead)
(Note that if the argument &quot;asfile&quot; is present then this argument is ''ignored'' - the argument &quot;saveformat&quot; is used instead)
Line 56: Line 45:
=== shape ===
=== shape ===


This option sets the outline shape of the shield, allowable values are:
This option sets the outline shape of the shield, allowable values are those shown in the preferences pane on the Drawshield.net create page.
 
{|
! Value
!align="center"| Shape
|-
| heater (default)
|align="center"| [[File:http://drawshield.net/create/img/heater.png|Example Shape]]
|-
| french
|align="center"| [[File:http://drawshield.net/create/img/french.png|Example Shape]]
|-
| oval
|align="center"| [[File:http://drawshield.net/create/img/oval.png|Example Shape]]
|-
| lozenge
|align="center"| [[File:http://drawshield.net/create/img/lozenge.png|Example Shape]]
|-
| square
|align="center"| [[File:http://drawshield.net/create/img/square.png|Example Shape]]
|-
| italian
|align="center"| [[File:http://drawshield.net/create/img/italian.png|Example Shape]]
|-
| swiss
|align="center"| [[File:http://drawshield.net/create/img/swiss.png|Example Shape]]
|-
| english
|align="center"| [[File:http://drawshield.net/create/img/english.png|Example Shape]]
|-
| german
|align="center"| [[File:http://drawshield.net/create/img/german.png|Example Shape]]
|-
| polish
|align="center"| [[File:http://drawshield.net/create/img/polish.png|Example Shape]]
|-
| spanish
|align="center"| [[File:http://drawshield.net/create/img/spanish.png|Example Shape]]
|-
| flag
|align="center"| [[File:http://drawshield.net/create/img/flag.png|Example Shape]]
|}


=== ar ===
=== ar ===
Line 105: Line 53:
=== palette ===
=== 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, &quot;gules&quot; is to be represented as something resembling &quot;red&quot;). Various authorities have developed their own colour choices and drawshield supports the following option values:
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, &quot;gules&quot; is to be represented as something resembling &quot;red&quot;). Various authorities have developed their own colour choices and drawshield supports the option values shown on the preferences pane of the drawshield.net create page.
 
{|
! Value
!align="center"| Example Palette
|-
| drawshield (default)
|align="center"| [[File:http://drawshield.net/create/img/drawshield.png|Example Palette]]
|-
| wikipedia
|align="center"| [[File:http://drawshield.net/create/img/wikipedia.png|Example Palette]]
|-
| emoji
|align="center"| [[File:http://drawshield.net/create/img/emoji.png|Example Palette]]
|-
| wappenwiki
|align="center"| [[File:http://drawshield.net/create/img/wappenwiki.png|Example Palette]]
|-
| outline
|align="center"| [[File:http://drawshield.net/create/img/outline.png|Example Palette]]
|-
| bajuvarian
|align="center"| (N/A)
|}


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


=== Additional Colour Names ===
=== Additional Colour Names ===
Line 144: Line 69:
=== effect ===
=== 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 &quot;no filter&quot;) affect the colour values set by the palette. To get just the pure colours from your chosen palette select the &quot;plain&quot; value for effect. The available values are:
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 &quot;no filter&quot;) affect the colour values set by the palette. To get just the pure colours from your chosen palette select the &quot;plain&quot; value for effect. The available values are those shown in the preferences pane of the drawshield.net create page.


{|
=== asfile ===
! Value
!align="center"| Example Effect
! Explanation
|-
| shiny
|align="center"| [[File:http://drawshield.net/create/img/shiny.png|Example Palette]]
| Supposed to look like a metallic surface with a highlight in the top left and coloured shadows to lower right
|-
| plain (default)
|align="center"| [[File:http://drawshield.net/create/img/plain.png|Example Palette]]
| No filters, show the pure colours from the palette.
|-
| stonework
|align="center"| [[File:http://drawshield.net/create/img/stonework.png|Example Palette]]
| Supposed to look like a slightly roughened stone surface that has been overpainted with the shield.
|-
| plaster
|align="center"| [[File:http://drawshield.net/create/img/plaster.png|Example Palette]]
| Supposed to look like the design has been embossed into wet plaster but isn't really very good!
|-
| vellum
|align="center"| [[File:http://drawshield.net/create/img/vellum.png|Example Palette]]
| 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.
If this option is present then instead of returning the image the program will force the download of the image as a file


=== asfile ===
=== filename ===


If this option is present then instead of returning the image the program will force the download of the image as a file, called &quot;shield.svg&quot;, &quot;shield.png&quot; or &quot;shield.jpg&quot; depending on the setting of the &quot;saveformat&quot; option.
This is the name that will be used for a downloaded file, if it is not given then 'shield' will be used. A suffix appropriate suitable for the file type will be added if not already present. Note that some browsers seem to ignore this and use their own naming conventions.


=== saveformat ===
=== saveformat ===


This option selects the file format for the &quot;asfile&quot; option, it takes the same values as &quot;outputformat&quot; above.
This option selects the file format for the &quot;asfile&quot; option, it takes the same values as &quot;outputformat&quot; above, with the addition of:


=== printable (Deprecated) ===
* pdfltr - as a PDF file sized 8.5" x 11"
* pdfa4 - as a PDF file sized 210mm x 297mm


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.
=== printable ===
 
This option forces SVG output at a width of 100% of the window (so all the format, saving and size options are ignored). The intention is to open this in a separate window which can then be printed using the browser printing dialog. It is probably of limited use  in other contexts.


=== stage (Deprecated) ===
=== stage (Deprecated) ===


This used to provide debugging information but there is now more complete data available in the json format.
This was used to provide debugging information but there is now more complete data available in the json format. It has no effect.
 
[[Category: Technical]]

Latest revision as of 22:14, 22 October 2023

A Plea to API users

DrawShield is hosted on a very small AWS LightSail, with a fixed amount of resource, it does NOT scale under load. Please rate-limit your use of the remote API to no more than a handful of requests per second. Any more is likely to overload the server possibly causing it to fail.

Options for GET and POST

If the drawshield code is installed on a PHP enabled web-server (such as drawshield.net) it can be invoked either by a GET or a POST request. An example GET request 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. Note that, although this method simple it is not the most flexible as it cannot be used to generate a blazon from a file and there is an upper limit to the length of the URL that varies from server to server.

The HTTP POST request 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.

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.

Unrecognised arguments are silently ignored (this includes miss-spellings of the accepted arguments, so check your request carefully).

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.

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.

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 (or jpeg) - JPEG image
  • webp - Google's WebP Image Format
  • png - PNG image with a transparent background
  • json - This format combines several types of data in a JSON wrapper, see The JSON Output Format

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

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.

shape

This option sets the outline shape of the shield, allowable values are those shown in the preferences pane on the Drawshield.net create page.

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.

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 option values shown on the preferences pane of the drawshield.net create page.

You can define your own colour palette, following the instructions here Defining Colour Palettes.

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

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 those shown in the preferences pane of the drawshield.net create page.

asfile

If this option is present then instead of returning the image the program will force the download of the image as a file

filename

This is the name that will be used for a downloaded file, if it is not given then 'shield' will be used. A suffix appropriate suitable for the file type will be added if not already present. Note that some browsers seem to ignore this and use their own naming conventions.

saveformat

This option selects the file format for the "asfile" option, it takes the same values as "outputformat" above, with the addition of:

  • pdfltr - as a PDF file sized 8.5" x 11"
  • pdfa4 - as a PDF file sized 210mm x 297mm

printable

This option forces SVG output at a width of 100% of the window (so all the format, saving and size options are ignored). The intention is to open this in a separate window which can then be printed using the browser printing dialog. It is probably of limited use in other contexts.

stage (Deprecated)

This was used to provide debugging information but there is now more complete data available in the json format. It has no effect.