tiff-kit-laravel maintained by mendesalexandre
tiff-kit-laravel
Laravel wrapper for tiffkit: convert large multi-page TIFF files
to PDF/A or PNG with very low memory use. The heavy work happens in a separate Rust process, so PHP's
memory_limit stops being a problem for big scanned books.
Install
-
Install the
tiffkitbinary (Linux x86_64) from the releases and put it on thePATH, e.g./usr/local/bin/tiffkit:curl -fsSL -o /tmp/tiffkit.tar.gz https://github.com/mendesalexandre/tiff-kit/releases/download/v0.5.0/tiffkit-v0.5.0-linux-x86_64.tar.gz tar -xzf /tmp/tiffkit.tar.gz -C /usr/local/bin tiffkit -
Install the package:
composer require mendesalexandre/tiff-kit-laravel php artisan vendor:publish --tag=tiff-kit-config # optional
Usage
use TiffKit\Laravel\Facades\TiffKit;
$pages = TiffKit::info('/data/book.tif'); // list<PageInfo>: width, height, compression, color
$result = TiffKit::toPdf('/data/book.tif', '/data/out'); // /data/out/book.pdf (PDF/A-3b, PDF 1.7)
$result->pages; // 554
$result->outputs; // ['/data/out/book.pdf']
TiffKit::toPdf($file, $dir, pdfaMode: 2); // PDF/A-2b
TiffKit::toPdf($file, $dir, pdfaMode: 0); // plain PDF 1.7 (NOT PDF/A)
TiffKit::toPng($file, $dir); // one grayscale PNG per page
// Several files, in parallel; any case of extension (.tif .TIF .tiff .TIFF)
$files = TiffKit::findTiffs('/data/books');
TiffKit::toPdfMany($files, '/data/out', jobs: 4);
Errors raise TiffKit\Laravel\Exceptions\TiffKitException (with exitCode and stderr). The PDF is only
published under its final name when every page was converted; otherwise nothing is left behind.
Treat any exception as "not converted" and keep the original TIFF.
Use it inside a queued job for long conversions: the timeout (default 600 s) and parallelism are configurable.
Configuration (config/tiff-kit.php / env)
| Env | Default | Meaning |
|---|---|---|
TIFFKIT_BIN |
tiffkit |
Path to the binary |
TIFFKIT_TIMEOUT |
600 |
Seconds before the process is killed (0 = no limit) |
TIFFKIT_PDFA_MODE |
3 |
2, 3, or 0 for plain PDF |
TIFFKIT_DEFAULT_DPI |
300 |
Resolution when the TIFF has none |
TIFFKIT_JOBS |
1 |
Parallel files in *Many methods |
Notes
- Digital signing (e.g. ICP-Brasil certificates) is out of scope: sign the produced PDF with your own tool.
- No OCR / text layer.
- Tests:
composer install && TIFFKIT_BIN=/path/to/tiffkit vendor/bin/phpunit(integration tests are skipped without the binary).
License
MIT.