---
title: "Printing Images"
description: "Printing Images"
type: "docs"
category: "doc"
tags: []
authors: [Anonymous]
date: "2026-09-09"
last_update: "2026-09-09"
time_minutes: 2
draft: false
unlisted: false
url: "https://www.derafu.dev/docs/utils/escpos/images"
---

# 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

```php
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:

```php
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`](https://github.com/tecnickcom/tc-lib-barcode), a required dependency) that you then print like any other image:

```php
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.



---
Last updated on 09/09/2026

