mykemeynell / filepreview
Library for generating file previews.
Installs: 6
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/mykemeynell/filepreview
Requires
- nesbot/carbon: ^2.30
- phpoffice/phpword: ^0.17.0
- symfony/http-foundation: ^5.0
- tecnickcom/tcpdf: ^6.3
Requires (Dev)
- larapack/dd: ^1.1
This package is auto-updated.
Last update: 2025-10-04 22:57:45 UTC
README
Generate preview images for file types.
Installation with Composer
composer require mykemeynell/filepreview
Usage
$fileName = '/path/to/file.pdf'; $preview = mykemeynell\FilePreview\FilePreview::fromPath($fileName); echo $preview->preview()->stream();
FilePreview::preview()
Actions the conversion and prepares headers for output.
FilePreview::stream()
Sets appropriate headers prepared in FilePreview::stream() and outputs
the content.
Custom Handlers
If you wish to change how MIME types are handled, then you can use the
FilePreview::addHandler($mime, $handler) method.
$handler can accept two parameters
- [Parameter 0] Instance of
FilePreview. - [Parameter 1] Instance of
mykemeynell\FilePreview\FileSystem\File::classrelating to the given file path.
FilePreview::addHandler('application/pdf', function ($preview, $file) { /** @var \mykemeynell\FilePreview\FilePreview $preview */ /** @var \mykemeynell\FilePreview\FileSystem\File $file */ // $content = ...= $preview->setContentTypeHeader('image/jpg'); $preview->setContent($content); return $preview; });