API Dokumentation

How to use GravAPI

Get JSON data

Fonts

http://yourkey.gravapi.com/json/get/fonts

Returns a list of all supported fonts in JSON Format:

[
 {
  "id": "parisienne",
  "name": "Parisienne",
  "googleName": "Parisienne",
  "googleUrl": "http:\/\/fonts.googleapis.com\/css?family=Parisienne"
 },
 ...
]

Symbols

http://yourkey.gravapi.com/json/get/symbols

Returns a list of all available symbols in JSON Format:

[
 {
  "id": "ring1",
  "names": {
    "de_DE": "Eheringe",
    "en_US": "Wedding band",
  },
  "width": "20",
  "height": "20"
 },
 ...
]

Get PNGs

Text Gravure (one line preview)

http://yourkey.gravapi.com/png/get/texts/font/parisienne?term=abc

Returns the term “abc” of the font with ID “parisienne” as PNG for the defined font size (default is font-size 208pt). It is also possible to recolor the png by setting the „rgba“ value as GET parameter. Please notice that the alpha value must be a number between 0 (no transparency) and 127 (full transparency). For engraving special chars, url-encoding is recommanded.
The following code demonstrates the usage. You can simply bind the URL in a source attribute of an image:

<img src="http://yourkey.gravapi.com/png/get/texts/font/parisienne/size/10?term=abc&rgba=255,255,255,30"/>

It is also possible, to get the PNG as base64 encoded data string. Use the „base64=1“ parameter of the URL in the following way:

$.ajax({
   url: "http://yourkey.gravapi.com/png/get/texts",
   data: { 
      font : "parisienne",
      term : "abc",        //Backslash and Double Quote must be escaped
      size : "10",         //by default: "208"
      rgba: "0,0,255,30",  //by default: "0,0,0,0" (black)
      base64 : 1           //by default: "0"
   }
   method: "GET",
}).success(function (data) {
   $('#image').attr('src','data:image/png;base64,' + data);
});

Error Handling

  • Returns HTTP status „204 – No Content“ if the given font ID does not exist
  • Returns HTTP status „400 – Bad Request“ if ID is empty and/or term is empty

Symbol Gravure

http://yourkey.gravapi.com/png/get/symbols/symbol/star82

Returns the sylmbol with the ID „star82“ as PNG. It is possible to recolor the png by setting the „rgba“ value as GET parameter. Please notice that the alpha value must be a number between 0 (no transparency) and 127 (full transparency) The following code demonstrates the usage. You can simply bind the URL in a source attribute of an image:

<img src="http://yourkey.gravapi.com/png/get/symbols/symbol/star82/rgba/255,255,255,30"/>

It is also possible, to get the PNG as base64 encoded data string. Use the „base64=1“ parameter of the URL in the following way:

$.ajax({
   url: "http://yourkey.gravapi.com/png/get/symbols",
   data: { 
      symbol: "star82",
      rgba: "0,0,255,30",  //by default: "0,0,0,100" (black)
      base64 : 1           //by default: "0"
   }
   method: "GET",
}).success(function (data) {
   $('#image').attr('src','data:image/png;base64,' + data);
});

Error Handling

  • Returns HTTP status „204 – No Content“ if the given symbol ID does not exist
  • Returns HTTP status „400 – Bad Request“ if symbol is empty

Workpiece Gravure

http://yourkey.gravapi.com/png/get/workpieces

Returns a Base64 encoded PNG data string. You need to specify the information of the workpiece that should be previewed. For this reason you send the gravure information via POST method as JSON formated data. Units must be pt (point). The following code demonstrates the usage.

{
 "width": "160",           //width of the workpiece
 "height": "100",          //height of the workpiece
 "rgba" : "0,0,0,0"        //color of the text and symbols (by default: black)
 "texts":                  //text gravures of the workpiece
 [
  {
   "font": "arial",
   "term": "abc%2Fdef",    //Backslash and Double Quote must be escaped
   "size": "6",
   "left": "20",
   "bottom": "25"
  }, ...
 ],
 "symbols":                 //symbol gravures of the workpiece
 [
  {
   "id": "s_1",
   "width": "80",
   "left": "40",
   "bottom": "45"
  }, ...
 ]
}

You can simply bind the ajax result in a source attribute of an image using base64 decoding:

$.ajax({
   url: "http://yourkey.gravapi.com/png/get/workpieces",
   data: JSON.parse(your_json_string),
   method: "POST",
}).success(function (data) {
   $('#image').attr('src','data:image/png;base64,' + data);
});

Error Handling

  • Returns HTTP status „204 – No Content“ if one of the given font IDs does not exist
  • Returns HTTP status „400 – Bad Request“ if any parameter is null or empty
  • Returns HTTP status „409 – Conflict“ if at least one text or symbol gravure is out of bound. Each gravure have to be inside the workpiece width and height

Get EPS

Workpiece (one workpiece gravure)

http://yourkey.gravapi.com/eps/get/workpieces

Returns a single EPS file for sending to a milling machine. You need to specify the information of the workpiece that should be engraved. For this reason you send the gravure information via POST method as JSON formated data. Units must be pt (point). The following code demonstrates the usage.

{
 "width": "160",           //width of the workpiece
 "height": "100",          //height of the workpiece
 "texts":                  //text gravures of the workpiece
 [
  {
   "font": "arial",
   "term": "abc%2Fdef",    //Backslash and Double Quote must be escaped
   "size": "6",
   "left": "20",
   "bottom": "25"
  }, ...
 ],
 "symbols":                 //symbol gravures of the workpiece
 [
  {
   "id": "s_1",
   "width": "80",
   "left": "40",
   "bottom": "45"
  }, ...
 ]
}

You can simply bind the response as a blob object in your ajax success (as shown below) or save the responded data as string in your database:

$.ajax({
   url: "http://yourkey.gravapi.com/eps/get/workpieces",
   data: JSON.parse(your_json_string),
   method: "POST",
}).success(function (data) {
   var blob = new Blob([data]);
   var link = document.createElement('a');
   link.href = window.URL.createObjectURL(blob);
   link.download = "workpiece.eps";
   link.click();
});

Error Handling

  • Returns HTTP status „204 – No Content“ if one of the given font IDs or a symbol ID do not exist
  • Returns HTTP status „400 – Bad Request“ if any parameter is null or empty: required parameters are „width“, „height“, „texts“ and/or „symbols“
  • Returns HTTP status „401 – Unauthorized“ your are not allowed to use this function. Please contact our team for more information.
  • Returns HTTP status „409 – Conflict“ if at least one text or symbol gravure is out of bound. Each gravure have to be inside the workpiece width and height

Template (multiple workpiece gravure)

http://yourkey.gravapi.com/eps/get/templates

Generates a single EPS file for multiple engraving (more than one workpiece) with a milling machine and returns the URL to download the file. You need to specify the information of the workpieces that should be engraved. For this reason you send the information via POST method as JSON formated data. The coordinates (bottom and left values) within a workpiece are relative to the workpiece position. Units must be pt (point). The following code demonstrates the usage.

{
 "name": "xyz",            //name of the eps file, to identify the template
 "width": "160",           //width of the template
 "height": "100",          //height of the template
 "workpieces" : 
 [
  {
   "left": "0",            //horizontal position of the workpiece (relative to the template)
   "bottom": "0",          //vertical position of the workpiece (relative to the template)
   "width": "100",         //width of the workpiece
   "height": "100",        //height of the workpiece
   "texts":                //text gravures of the workpiece
   [
    {
     "font": "arial",
     "term": "abc%2Fdef",   //Backslash and Double Quote must be escaped
     "size": "6",
     "left": "20",          //horizontal position of the text (relative to the workpiece)
     "bottom": "25"         //vertical position of the text (relative to the workpiece)
    }, ...
   ],
   "symbols":               //symbol gravures of the workpiece
   [
    {
     "id": "s_1",
     "width": "80",
     "left": "40",          //horizontal position of the symbol (relative to the workpiece)
     "bottom": "45"         //vertical position of the symbol (relative to the workpiece)
    }, ...
   ]
  }, ...
 ] 
}

For example you can store the responded data (URL to the eps file) as string in your database:

$.ajax({
   url: "http://yourkey.gravapi.com/eps/get/templates",
   data: JSON.parse(your_json_string),
   method: "POST",
}).success(function (data) {
   ... //
});

Error Handling

  • Returns HTTP status „204 – No Content“ if one of the given font IDs or a symbol ID do not exist
  • Returns HTTP status „400 – Bad Request“ if any parameter is null or empty: required parameters for templates are: „width“, „height“, „workpieces“ and for each workpiece: „left“, „bottom“, „width“, „height“, „texts“ and/or „symbols“
  • Returns HTTP status „401 – Unauthorized“ your are not allowed to use this function. Please contact our team for more information.
  • Returns HTTP status „409 – Conflict“ if at least one text or symbol gravure is out of bound. Each gravure have to be inside the workpiece width and height