Home Contents | # gcx:save | Graphics | Core4 Lua Commands

## SYNOPSIS

1. gcx:save(filename[, ...])
2. gcx:save(handle, format [, ...])
3. data = gcx:encode(format [, ...])
4. gcx:saveat(x, y, width, height, filename[, ...])
5. gcx:saveat(x, y, width, height, handle, format [, ...])
6. data = gcx:encodeat(x, y, width, height, format [, ...])
7. gcx:saveat(rect, filename[, ...])
8. gcx:saveat(rect, handle, format [, ...])
9. data = gcx:encodeat(rect, format [, ...])

## DESCRIPTION

Save the image contents of the graphics context. The first form saves the data to a file named filename. The file format is automatically detected from the file extension.

The second form saves/sends the image to a file handle (which might be a serial port or network socket). The data format is indicated by the format variable.

The third form encodes the image data and returns it as a string. The data format is also indicated by the format variable.

The other forms allow selecting a specific rectangle out of the source bitmap. This can either be done with integer coordinates and sizes or with a rectangle object.

The format parameter selects the data encoding.

format | Description
--- | ---
"BMP" | Encode as standard uncompressed BMP bitmap image. 1bpp and 24bpp are supported. Every other bit depth is saved as 24bpp. Any transparency data is ignored.
"FPMRAW" | Encode data for immediate printing on a Teratronik HSP (High Speed Printer).
"FPMSTORE" | Save data to a Teratronik HSP (High Speed Printer). The image is saved in the printer's image buffer. The image can be printed by following up with the escape sequence 1B 2B 01, possibly after moving the cursor to the right place with 1B 7C xl xh yl yh. For backward compatibility, the format string "FPM" also selects this option. Takes two optional numeric parameters. The first enables RLL compression when non-zero. The second asks the image to be rotated before uploading (1=-90°, 2=0°, 3=+90°, 4=+180°, default is 2, which is equivalent to printer's landscape mode.)
"C56RAW" | Send data to a Hengstler C56 printer for immediate printing.
"C56STORE" | Save data to a Hengstler C56 printer's image buffer in flash memory. The command needs an additional parameter, the unique identification number of the image (1..255).
"X56RAW" | Send data to a Hengstler X56 printer for immediate printing.
"X80RAW" | Send data to a Hengstler X80 printer for immediate printing.
"PIXI" | Send data to a Hengstler PIXI printer for immediate printing.
"CUSTOM1B2A" | Send data to a Custom receipt printer for immediate printing, using the command sequence 1B 2A 21... Takes one optional string argument that overrides the code generated to feed lines. Default feed string is "\x1B\x4A\x18".
"CUSTOM1D2ABMP" | Save data to a CUSTOM printer's image buffer in flash memory, using the command sequence 1D 2A NN followed by a 1bpp BMP file. The command needs an additional parameter, the unique identification number of the image (0..1), which is inserted for NN into the byte stream. Typically used by TL60 and TL60-EJ.
"CUSTOM1BFF" | Save data to a CUSTOM printer's image buffer in flash memory, using the command sequence 1B FF... The command needs an additional parameter, the unique identification number of the image (1..2). To make this work, the width of the image must fit exactly to the requirements of the printer model. This command is typically used with the VKP80II, which requires a fixed widh of 608 pixels. The height can be variable, but there are printer model specific limits. (Note: There are older documents that claim the KPM180 supports this command, but the documentation is wrong. Use "CUSTOM1C94" encoding instead.)
"CUSTOM1C94" | Save data to a CUSTOM printer's image buffer in flash memory, using the command sequence 1C 94... The command takes two optional parameters, the unique identification number of the image (1..N, default 0) and a filename (max. 16 characters, default "LOGO.BMP"). Typically used by KPM180.
"~DY" | Encode data into a Zebra ZPL ~DY command. This builds a full ~DY command, using the GRF file format and ZB64 compression. The first optional parameter specifies the file name, which defaults to "R:LOGO.GRF". The second optional parameter specifies the zlib compression level. (-1 = no compression, 0 = default compression, 1..9 = level 1..9). The default compression level is typically a good compromise between time spent compressing and time spent transferring the data at 115200bps. The output of this command can be sent to a ZPL compatible printer directly without further encoding.

## RETURN VALUE

On success, the first and second forms return true, the third form returns the encoded data. On error, all forms return three values: nil, a string describing the error (The result of the C library call strerror() on the errno code) and the errno number from the standard C library.

## SEE ALSO

gcx:image, gcx:blit, gfx.open, gcx:close, gcx:pixmap, gcx:window