Printing Images

EscposPrinter::image() never asks for a type from the underlying ESC/POS library — it takes Derafu\Escpos\ValueObject\RasterImage, a small wrapper around a GD image (\GdImage). You decide how the pixels were produced; this package only knows how to print them.

From an existing GD resource

use Derafu\Escpos\ValueObject\RasterImage;

$gd = imagecreatefrompng('/path/to/logo.png');

$printer->image(new RasterImage($gd));

From raw image bytes

If you already have PNG bytes (downloaded, generated, read from a database, etc.) instead of a GD resource, decode them with the named constructor:

use Derafu\Escpos\ValueObject\RasterImage;

$logo = RasterImage::fromPngData(file_get_contents('/path/to/logo.png'));

$printer->image($logo);

fromPngData() throws Derafu\Escpos\Exception\InvalidImageDataException if the given bytes cannot be decoded as an image — it never returns a broken RasterImage.

PDF417 as a bitmap fallback

EscposPrinter::pdf417() sends the printer’s native PDF417 command. Some cheaper thermal printers do not support it. For those, Derafu\Escpos\Renderer\Pdf417Renderer renders a PDF417 code as a raster image (using tecnickcom/tc-lib-barcode, a required dependency) that you then print like any other image:

use Derafu\Escpos\Renderer\Pdf417Renderer;

$renderer = new Pdf417Renderer();
$image = $renderer->render('some-content-to-encode');

$printer->image($image);

This is a rendering concern, not a printing one, so it lives outside EscposPrinter on purpose: EscposPrinter has no idea Pdf417Renderer exists, and never will need to. You only reach for it when the native command does not work on your printer.

On this page

Last updated on 04/08/2026 by Anonymous