How to use the escpos.image.EscposImage function in escpos

To help you get started, we’ve selected a few escpos examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github python-escpos / python-escpos / test / test_image.py View on Github external
def test_split():
    """
    test whether the split-function works as expected
    """
    im = EscposImage('test/resources/black_white.png')
    (upper_part, lower_part) = im.split(1)
    upper_part = EscposImage(upper_part)
    lower_part = EscposImage(lower_part)
    assert(upper_part.width == lower_part.width == 2)
    assert(upper_part.height == lower_part.height == 1)
    assert(upper_part.to_raster_format() == b'\xc0')
    assert(lower_part.to_raster_format() == b'\x00')
github python-escpos / python-escpos / test / test_image.py View on Github external
def _load_and_check_img(filename, width_expected, height_expected, raster_format_expected, column_format_expected):
    """
    Load an image, and test whether raster & column formatted output, sizes, etc match expectations.
    """
    im = EscposImage('test/resources/' + filename)
    assert(im.width == width_expected)
    assert(im.height == height_expected)
    assert(im.to_raster_format() == raster_format_expected)
    i = 0 
    for row in im.to_column_format(False):
        assert(row == column_format_expected[i])
        i += 1
github python-escpos / python-escpos / src / escpos / escpos.py View on Github external
The available printing implementations are:

            * `bitImageRaster`: prints with the `GS v 0`-command
            * `graphics`: prints with the `GS ( L`-command
            * `bitImageColumn`: prints with the `ESC *`-command

        :param img_source: PIL image or filename to load: `jpg`, `gif`, `png` or `bmp`
        :param high_density_vertical: print in high density in vertical direction *default:* True
        :param high_density_horizontal: print in high density in horizontal direction *default:* True
        :param impl: choose image printing mode between `bitImageRaster`, `graphics` or `bitImageColumn`
        :param fragment_height: Images larger than this will be split into multiple fragments *default:* 960
        :param center: Center image horizontally *default:* False

        """
        im = EscposImage(img_source)

        try:
            max_width = int(self.profile.profile_data['media']['width']['pixels'])

            if im.width > max_width:
                raise ImageWidthError('{} > {}'.format(im.width, max_width))

            if center:
                im.center(max_width)
        except KeyError:
            # If the printer's pixel width is not known, print anyways...
            pass
        except ValueError:
            # If the max_width cannot be converted to an int, print anyways...
            pass