epskit / epskit
Pure-PHP toolkit for EPS files: previews, EPS to PDF conversion, and EPS / PDF / Illustrator thumbnails with PDFium, without Ghostscript.
Requires
- php: >=8.1
- ext-zlib: *
Requires (Dev)
None
Suggests
- ext-dom: Needed to write XMP metadata into thumbnails (metadata / copyMetadata options)
- ext-ffi: Fast in-process PDF rendering with the bundled PDFium library (otherwise the bundled pdfium-cli program is used)
- ext-gd: Needed to convert JPEG previews to PNG and to write images rendered through FFI
Provides
None
Conflicts
None
Replaces
None
README
PHP toolkit for EPS (Encapsulated PostScript-compatible), PDF and Illustrator files, without Ghostscript: preview extraction and EPS → PDF conversion in pure PHP, and thumbnails of EPS / PDF / .ai files rendered with PDFium.
Usage
Create the converter
$epskit = new Epskit\Epskit();
Thumbnail of an .eps, .ai or .pdf file
The image is written to the output file; its extension (.png, .jpg) chooses the format. By default
the resolution is 160 dpi, so the image has the artwork's own size.
$epskit->convertThumbnail('artwork.eps', 'artwork.png');
Thumbnail that fits in a box
The image is made smaller to fit in 200 × 200 px (aspect ratio kept, never enlarged).
$epskit->convertThumbnail('artwork.ai', 'artwork_s.jpg', maxWidth: 200, maxHeight: 200);
Resolution (dpi)
160 dpi is the default. Any other resolution can be given, e.g. 72 dpi (one pixel per point):
$epskit->convertThumbnail('artwork.eps', 'artwork.png', dpi: 72);
The resolution written into the image file is dpi by default; resolutionTag writes another value
without changing the pixels (e.g. 72, as the CMS did for its small thumbnails):
$epskit->convertThumbnail('artwork.eps', 'artwork_s.jpg', dpi: 160, resolutionTag: 72);
| dpi | A 100 × 50 pt artwork becomes |
|---|---|
| 72 | 100 × 50 px |
| 160 (default) | 222 × 111 px |
| 300 | 417 × 208 px |
Sharpening
Thumbnails are sharpened slightly after rendering, as image programs do when they make images smaller:
smoothing spreads a line about one pixel wide over two lighter pixels, so thin lines would look faint in
small thumbnails, and photos would lose some detail. sharpen: 0 turns it off (0.2 is the default; 0.35
starts to show halos). Images over 16 million pixels are not sharpened.
$epskit->convertThumbnail('artwork.eps', 'artwork.png', sharpen: 0);
Metadata
Thumbnails carry no metadata unless asked (only their resolution). XMP metadata, which Photoshop, Bridge, Lightroom and Windows read, can be written into the JPEG or PNG:
$epskit->convertThumbnail('artwork.eps', 'artwork.jpg', metadata: [ 'title' => 'Turning tool holder', 'creator' => ['Design team'], 'copyright' => '© Example Co.', 'keywords' => ['turning', 'holder'], 'assetId' => 'A-001', // names of your own are stored as epskit:assetId ]); // the source file's own XMP (title, author, dates, document IDs…), with your fields over it $epskit->convertThumbnail('artwork.ai', 'artwork.jpg', copyMetadata: true, metadata: ['assetId' => 'A-001']);
Fields with a short name: title, description, creator (list), copyright, keywords (list),
source, created, rating, credit, copyrightUrl. Copied packets leave out the source's embedded
thumbnails and edit history, and are trimmed to their essential parts when still over 65 000 bytes (the
size of one JPEG metadata segment). Needs ext-dom (part of the usual PHP builds).
Multi-page PDF files
The first page is rendered; another one is chosen with page. PDF files (and Illustrator 9+ files) are
read by PDFium block by block, only what that page needs, so large multi-page documents are fast and use
little memory in PHP.
$epskit->convertThumbnail('catalog.pdf', 'catalog_p3.jpg', page: 3);
Thumbnail in memory
Without an output file, the image stays in memory.
$thumb = $epskit->convertThumbnail('artwork.pdf'); echo $thumb->width . ' x ' . $thumb->height; $png = $thumb->image; // PNG bytes
EPS → PDF
$result = $epskit->convertPdf('artwork.eps', 'artwork.pdf'); foreach ($result->warnings as $warning) { echo $warning, "\n"; // e.g. a font that was substituted }
Errors
Every failure is an Epskit\EpskitException (a RuntimeException, so catch (Exception $e) also catches
it), including unexpected internal errors: epskit never stops the application. That covers files of the
wrong type (only .eps, .ai and .pdf, with contents matching the extension), damaged files, a page
that does not exist, and files too large for the memory or time that php.ini leaves.
try { $epskit->convertThumbnail($input, $output); } catch (Epskit\EpskitException $e) { echo 'Cannot make a thumbnail: ' . $e->getMessage(); }
PHP warnings raised inside epskit are kept away from the application's error handler. An EPS whose
PostScript stops on an error still gives an image of what was drawn; $thumb->conversion->complete is
then false and $thumb->conversion->failure says why.
Options of convertThumbnail()
| Option | Default | Meaning |
|---|---|---|
dpi |
160 | Resolution; the image has the artwork's size at this resolution |
maxWidth, maxHeight |
none | If the image would be larger, it is made smaller to fit (aspect ratio kept, never enlarged) |
format |
from the output file name, else PNG | png or jpeg |
quality |
90 | JPEG quality |
page |
1 | Page of a PDF |
resolutionTag |
dpi |
Resolution written into the file (JPEG JFIF / PNG pHYs), only metadata that layout programs use for the printed size; the pixels do not change. The CMS wrote 72 into its small thumbnails |
sharpen |
0.2 | Light sharpening after rendering, so thin lines stay clear in small images; 0: off |
metadata |
none | XMP fields written into the image (see Metadata) |
copyMetadata |
false | Copy the source file's own XMP into the image |
Command line
vendor/bin/epskit thumbnail artwork.ai artwork.png --dpi=160 --max-width=400 --max-height=400
vendor/bin/epskit thumbnail artwork.eps artwork_s.jpg --dpi=160 --resolution-tag=72
vendor/bin/epskit thumbnail artwork.ai artwork.jpg --copy-metadata --meta=assetId=A-001 --meta=keywords=turning,holder
Status
Early development, used internally. EPS → PDF conversion writes paths, fills, strokes, clipping, colors (spot colors kept), images, smooth shadings, patterns and text in embedded Type 1 / Type 3 / CID-keyed fonts (e.g. Japanese fonts embedded by Illustrator). Fonts that are not embedded are drawn with substitute fonts found on the computer (see Fonts that are not embedded).
Requirements
- PHP 8.1 or later with
ext-zlibandext-gd. ext-ffienabled (ffi.enable=true) for fast thumbnails — recommended, see Enable FFI on the server.
Installation
composer require epskit/epskit
The package is on Packagist; the PDFium library and program for Windows x64 and Linux x64 come with it.
Enable FFI on the server (recommended)
Thumbnails work without any configuration, but then each one takes about 2–3 s (the bundled pdfium-cli
program is started every time). With PHP's FFI extension enabled, PDFium runs inside PHP: about
20–700 ms per thumbnail. Composer cannot change php.ini, so do this once on each server:
; php.ini used by the web server (Apache, PHP-FPM) and by the command line extension=ffi ffi.enable=true
- Windows:
php_ffi.dllships with PHP in theextfolder; remove the;in front ofextension=ffi, and changeffi.enablefrom its defaultpreload(which only works on the command line) totrue. - Linux: FFI is part of the usual PHP packages (e.g. Ubuntu
php8.x-cli/php8.x-fpm); setffi.enable=truein the php.ini of the web server (e.g./etc/php/8.x/apache2/php.inior/etc/php/8.x/fpm/php.ini). - Restart the web server, then check:
php -r "var_dump(extension_loaded('ffi'), ini_get('ffi.enable'));"on the command line, and the FFI section ofphpinfo()for the web server.
ffi.enable=true lets PHP code on that server load native libraries; keep it to servers whose PHP code
you control.
How thumbnails are made
PDF files and Illustrator 9+ files (which are PDF files) are rendered by
PDFium; EPS files and Illustrator 3–8 files (PostScript) are
first converted to PDF by Epskit\EpsToPdf, then rendered. The image covers the page (PDF) or the
bounding box (EPS), on white.
Files saved in the native format of Illustrator 3–6 cannot be drawn: they do not contain the PostScript
procedures their drawing commands need (only Illustrator itself understands them; Ghostscript cannot draw
them either). convertThumbnail() then throws an EpskitException saying so. Illustrator 7 and 8 files
include the procedures and are drawn.
PDFium is bundled for Windows x64 and Linux x64 in resources/pdfium/ (nothing else to install): the
PDFium library and the pdfium-cli program (klippa-app/pdfium-cli,
PDFium built as WebAssembly in one executable). epskit uses the library through PHP's FFI extension when it
is enabled (extension=ffi and ffi.enable=true in php.ini; fast, in-process), and otherwise runs the
program (no php.ini change; about 2–3 s per image). With FFI a size limit is applied while rendering;
with the program the image is scaled down with GD. Other platforms, or another PDFium, can be used with
the EPSKIT_PDFIUM environment variable or new Epskit\Epskit(Epskit\Render\Pdfium::renderer('/path')).
Files are passed in memory, so file names in any language work.
The lower-level classes behind Epskit are Epskit\Thumbnailer, Epskit\EpsToPdf and
Epskit\Render\Pdfium.
Colors
- EPS files from Photoshop (and some others) store the ICC profile their colors are meant in
(
%%BeginICCProfile), e.g. Japan Color 2001 Coated for CMYK or Dot Gain 20% for grey.EpsToPdfwrites it into the PDF as the color space of those colors and images, so they look as in Photoshop (a CMYK photo is not shifted towards pink, a greyscale image has Photoshop's tone curve). - PDF and Illustrator files carry their profiles themselves; PDFium uses them.
- Device colors without a profile are converted by PDFium; grey is drawn with the gamma 1.8 display curve that Adobe applications and Ghostscript use.
Previews stored in EPS files
Many EPS files carry a preview image that can be read without interpreting any PostScript:
$eps = Epskit\EpsFile::fromFile('artwork.eps'); $best = (new Epskit\PreviewExtractor())->extract($eps)->best(200); // long side >= 200 px, or null if ($best !== null) { file_put_contents('preview.png', $best->toPng()); } echo $eps->dsc()->creator(); // DSC header comments, e.g. the application print_r($eps->boundingBox()); // [llx, lly, urx, ury] in points
| Source | Typical producer | Notes |
|---|---|---|
Full raster image (%ImageData) |
Photoshop EPS | Original pixels: grayscale, bitmap, duotone, RGB, CMYK, Lab; JPEG, hex, ASCII85 or binary encoding |
XMP thumbnail (xmpGImg) |
Illustrator CS5 and later, other Adobe apps | JPEG, long side up to 256 px |
| TIFF preview in the DOS EPS header | Most Windows / cross-platform EPS writers | Uncompressed, LZW, PackBits; 1–16 bit; gray, RGB, palette, CMYK, alpha |
| Photoshop thumbnail resource (8BIM 1036/1033) | Photoshop EPS | JPEG, up to 160 px |
EPSI preview (%%BeginPreview) |
Various | 1–8 bit grayscale |
| WMF preview in the DOS EPS header | Some Windows apps | Listed only (not decoded) |
Command line: vendor/bin/epskit info|preview|extract artwork.eps … (run vendor/bin/epskit for help).
Fonts that are not embedded
EPS files often name fonts without embedding them: Japanese fonts such as KozGoPr6N-Regular-90ms-RKSJ-H
(a CIDFont plus a CMap) or base fonts such as Arial-BoldMT. EpsToPdf draws such text with substitute
fonts, with nothing to configure:
- the CMaps it needs (Adobe-Japan1 and Identity, from Adobe's
cmap-resources, BSD-3-Clause) and a CID → Unicode
table are bundled in
resources/; - glyphs come from the fonts of the operating system: Yu Gothic or MS Gothic, Arial, Times New Roman and
Courier New on Windows; Noto Sans CJK and Liberation on Linux; Hiragino and Arial on macOS. A font
placed in
resources/fonts/(OpenType or TrueType, e.g. Noto Sans CJK JP) is used before the system's Japanese font.
OpenType (CFF) and TrueType fonts, including collections (.ttc), can be used. Other choices:
use Epskit\PostScript\FontResources; use Epskit\PostScript\Fonts\CidSubstitute; $resources = new FontResources( cmapDirs: [FontResources::BUNDLED . '/cmap'], cidFonts: ['Adobe-Japan1' => new CidSubstitute('/opt/fonts/NotoSansCJKjp-Regular.otf', FontResources::BUNDLED . '/cid2unicode/Adobe-Japan1.bin.gz', CidSubstitute::JAPAN1_HALF_WIDTH)], fonts: ['Arial-BoldMT' => '/opt/fonts/arialbd.ttf'], families: FontResources::systemFamilies(), // sans / serif / mono for other base fonts ); $result = (new Epskit\EpsToPdf(fontResources: $resources))->convert($eps); $result = (new Epskit\EpsToPdf(fontResources: new FontResources()))->convert($eps); // no substitutes
With Epskit, pass them as new Epskit\Epskit(fonts: $resources). A substitute keeps the text and its
layout but not the original typeface; each one is listed in the warnings.
PostScript interpreter (in progress)
Epskit\PostScript\Interpreter is a LanguageLevel 3 interpreter written from the PostScript Language
Reference: scanner, execution loop, error handling (errordict, stopped), save/restore, about 300
operators, filters (ASCIIHex, ASCII85, RunLength, LZW, Flate, SubFile, ReusableStream; DCT is delimited and
passed through), eexec, resources and CMaps, graphics state, paths, colors, Type 1 charstrings, Type 3
fonts, CID-keyed fonts (CMaps, CIDFontType 0, horizontal and vertical writing) and, for substitute fonts,
OpenType CFF outlines (Type 2 charstrings). Painting operations go to a Device; Epskit\Pdf\PdfDevice writes them as one PDF page.
$vm = new Epskit\PostScript\Interpreter(); // NullDevice: counts painting operations $ok = $vm->run($eps->postScript()); // false: $vm->failure says what stopped it
Safety
Uploaded files are untrusted input; epskit is written so that a hostile or broken file cannot take the application down or reach the server:
- No file system or shell access from the file. The PostScript interpreter has no file operators
(
file,run,deletefile,renamefilefail withinvalidfileaccess; only%stdout/%stderrexist, captured in memory). Bundled CMaps are only looked up by checked names in their own folder. The pdfium-cli program is started without a shell, with arguments that cannot be read as options. - Limits that stop before PHP does. Operations, time, memory, stack depths, string and array sizes
are limited (
Epskit\PostScript\Limits); time and memory default to whatmax_execution_timeandmemory_limitleave, because PHP's own fatal errors cannot be caught. Sizes are checked before large allocations (images, files read into memory). - Decompression bombs. Flate, LZW and RunLength data, and image samples, may only expand within the
memory left; past that the program fails with
limitcheck. - Unbounded recursion. Nested procedures run by operators, nested arrays and functions are limited.
- PDFium. Pages are rendered with a time limit. A crash inside PDFium (a native library) would end
the PHP process when it runs through FFI; for files from untrusted sources use
new Epskit\Epskit(isolate: true), which runs PDFium in a separate process. - Preview extraction never executes PostScript, checks every offset and length, and limits image sizes (50 million pixels by default).
- Temporary files (only with the pdfium-cli program) are created with unique names in the system temporary folder and removed afterwards.
Development
php tests/run.php
The test suite builds all its fixtures in memory; no third-party sample files are stored in this repository.
tools/check-samples.php runs the extractor over a local folder of real files and can compare the
results with a reference renderer. It is a development aid only.
tools/build-resources.php path/to/cmap-resources regenerates resources/ from Adobe's CMap resources.
Clean-room statement
epskit is written from public specifications only: Adobe's PostScript Language Reference (3rd ed.),
Encapsulated PostScript File Format Specification 3.0, Document Structuring Conventions
Specification 3.0, Adobe technical notes 5014 (CID-keyed fonts), 5176 (CFF) and 5177 (Type 2
charstrings), the OpenType, TIFF 6.0 and XMP specifications. It contains no code derived
from Ghostscript or other PostScript interpreters, and no Adobe fonts or procedure sets. The PDFium
builds and the CMap data in resources/ are third-party components, distributed unchanged under their
own licenses (see THIRD-PARTY-NOTICES.md).
PostScript, Photoshop and Illustrator are trademarks of Adobe. epskit is not affiliated with Adobe.
License
Copyright 2026 Tran Ba Dai.
epskit's own code: Apache License 2.0, see LICENSE and NOTICE. Bundled third-party components (PDFium, CMap resources) keep their licenses, all permissive: see THIRD-PARTY-NOTICES.md.