spatie/pdf-to-image
Convert PDF pages to images with this simple PHP class built on Imagick and Ghostscript. Save as jpg, jpeg, png, or webp, render any page, and check page counts. Requires PHP 8.2+.
Feature bets this unblocks (fast, cheap):
thumbnailSize() thumbnail is one call. This is the single highest-leverage use case and typically a "table stakes" gap in B2B document products.selectPage() / selectPages() / saveAllPages() lets you build a page-strip or carousel rather than a single cover image.resolution(300) to produce print-proof or pre-flight previews for a "this is what will be printed/mailed" confirmation step.format(OutputFormat::Webp) plus quality() makes "store WebP derivatives, serve JPEG fallback" a one-line config choice rather than a research spike.Build vs. buy: This is a buy decision that is really an infrastructure decision. The code is ~free (MIT, mature, Spatie-maintained); your actual investment is Ghostscript + ImageMagick on your PHP hosts and the operational work of running them safely. Framing it as "we write a wrapper class" is wrong — the wrapper is trivial, the binary dependency is not. Decide both together.
Roadmap sequencing: Because it is a small, boring, low-lock-in dependency (a single class, no service provider, no database), it is a good candidate for a spike-to-ship in one sprint for the preview feature. Don't let it sit on a roadmap as a "document rendering platform" initiative; that framing invites scope creep toward text extraction, editing, and annotation — none of which this package does.
Derivative storage strategy: save() returns a path (or array of paths for multi-page), so you must decide product-side: generate derivatives on upload (predictable, storage cost, instant previews) vs. on demand (cheaper storage, latency, needs caching). This package supports either; the decision is yours and it's a real cost/latency trade-off, not a technicality.
What this explicitly does not decide: searchable text, OCR, PDF generation/merge/split, redaction, annotation, form filling, digital signatures. If a stakeholder request contains those words, this package is one ingredient at most.
Adopt when most of these hold:
policy.xml and php-fpm.conf (the README's two gotchas — FailedToExecuteCommand 'gs' under FPM and the security policy 'PDF' coder restriction — will otherwise burn a day of engineering).password() only works on ImageMagick 7 and throws PasswordNotSupported on IM6; verify with Pdf::supportsPasswordProtectedPdfs() before promising this to customers.Look elsewhere when:
policy.xml width/height limits), and file-size/type validation are your responsibility, not the package's. If you can't staff that, use a managed rendering service or an isolated worker.pdftotext) or OCR is a separate dependency; don't let anyone assume "PDF to image" gives you search.policy.xml width/height workaround signals real failure modes; validate against your actual document corpus first.Signal-quality caveat for the decision log: 1,460 stars and a Spatie-authored, MIT-licensed package with a changelog and recent releases indicate mature and low maintenance risk. The "0 dependents" figure is not a credible adoption signal (Packagist dependent counts are notoriously incomplete) — do not cite it as evidence of low usage in a build-vs-buy memo.
For executives (one paragraph): We can close a visible product gap — document thumbnails and page previews — with a mature, MIT-licensed open-source library instead of a paid rendering service or a custom build. The library itself is small and low-risk, maintained by Spatie, and requires no new vendor contract. The real commitment is modest but not zero: our servers must run Ghostscript and ImageMagick, which means a small amount of infrastructure hardening and a security review for how we handle customer-uploaded PDFs. Expect roughly one sprint to ship previews on trusted documents; untrusted uploads at scale should get a sandboxing review or a managed service, and any on-prem/enterprise distribution needs a licensing check because Ghostscript is AGPL. Recommendation: approve for the preview/thumbnail feature now, scoped to authenticated business documents, on background workers.
For engineering (the short version): spatie/pdf-to-image v3, PHP 8.2+, MIT. Plain class, no Laravel provider, trivial API (new Pdf($path)->selectPages(1,2)->thumbnailSize(400)->save($dir)). It does not generate, split, merge, extract text, redact, or annotate PDFs — rasterization only. Hard dependencies are Ghostscript + ImageMagick, which is where all the risk lives:
policy.xml (PDF coder read/write; width/height limits for ultra-wide docs) and php-fpm.conf env[PATH] so FPM can find gs.pageCount()) and cap pages rendered per document.Pdf::supportsPasswordProtectedPdfs().Ask: approve the dependency and the Ghostscript/ImageMagick host requirement for the preview epic; treat document-rendering hardening as a named work item, not incidental plumbing.
How can I help you explore Laravel packages today?