PHPackages                             drenso/pdf-to-image - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. drenso/pdf-to-image

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

drenso/pdf-to-image
===================

Convert a pdf to an image

3.0.0(2y ago)169.0k↓30.6%MITPHPPHP &gt;=8.2

Since Feb 13Pushed 2y agoCompare

[ Source](https://github.com/Drenso/pdf-to-image)[ Packagist](https://packagist.org/packages/drenso/pdf-to-image)[ Docs](https://github.com/drenso/pdf-to-image)[ GitHub Sponsors](https://github.com/spatie)[ RSS](/packages/drenso-pdf-to-image/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

Convert a pdf to an image
=========================

[](#convert-a-pdf-to-an-image)

[![Latest Version on Packagist](https://camo.githubusercontent.com/605ae9b5a5f967053599ea68c31dd51e702ba18481490ee760a2429fdc07aafb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f7064662d746f2d696d6167652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/pdf-to-image)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](.github/LICENSE.md)[![Quality Score](https://camo.githubusercontent.com/3d8bf7a5915bc81f2bd8a1d5578106208216f0ccc6c89e6d1c627385ced1143c/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7370617469652f7064662d746f2d696d6167652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/spatie/pdf-to-image)[![StyleCI](https://camo.githubusercontent.com/de2459259700666ebb9970f2c3e4c02888ff3bb4a121a7cd955f3c0001969fb8/68747470733a2f2f7374796c6563692e696f2f7265706f732f33383431393630342f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/38419604)[![Total Downloads](https://camo.githubusercontent.com/d6855f78defae657a3d40fb74cf546d576726907dbc0a17048f6877fa9874e13/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f7064662d746f2d696d6167652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/pdf-to-image)

This package provides an easy to work with class to convert PDF's to images. It is based on the [`spatie/pdf-to-image`](https://github.com/spatie/pdf-to-image) library, which relied on Imagick for the conversion. This library relies on GD instead.

Requirements
------------

[](#requirements)

You should have [Ghostscript](http://www.ghostscript.com/) installed. See [issues regarding Ghostscript](#issues-regarding-ghostscript).

Installation
------------

[](#installation)

The package can be installed via composer:

```
composer require drenso/pdf-to-image
```

Usage
-----

[](#usage)

Converting a pdf to an image is easy.

```
$pdf = new Drenso\PdfToImage\Pdf($pathToPdf);
$pdf->saveImage($pathToWhereImageShouldBeStored);
```

If the path you pass to `saveImage` has the extensions `jpg`, `jpeg`, or `png` the image will be saved in that format. Otherwise the output will be a jpg.

Other methods
-------------

[](#other-methods)

You can get the total number of pages in the pdf:

```
$pdf->getNumberOfPages(); //returns an int
```

By default the first page of the pdf will be rendered. If you want to render another page you can do so:

```
$pdf->setPage(2)
    ->saveImage($pathToWhereImageShouldBeStored); //saves the second page
```

You can override the output format:

```
$pdf->setOutputFormat(ExportFormatEnum::PNG)
    ->saveImage($pathToWhereImageShouldBeStored); //the output wil be a png, no matter what
```

You can set the quality of compression (this depends on the export format, see the GD documentation for more details):

```
$pdf->setCompressionQuality(100); // sets the compression quality to maximum
```

You can specify the width to scale down the resulting image:

```
$pdf
   ->setWidth(400)
   ->saveImage($pathToWhereImageShouldBeStored);
```

Issues regarding Ghostscript
----------------------------

[](#issues-regarding-ghostscript)

This package uses Ghostscript through Imagick. For this to work Ghostscripts `gs` command should be accessible from the PHP process. For the PHP CLI process (e.g. Laravel's asynchronous jobs, commands, etc...) this is usually already the case.

However for PHP on FPM (e.g. when running this package "in the browser") you might run into the following problem:

```
Uncaught ImagickException: FailedToExecuteCommand 'gs'

```

This can be fixed by adding the following line at the end of your `php-fpm.conf` file and restarting PHP FPM. If you're unsure where the `php-fpm.conf` file is located you can check `phpinfo()`. If you are using Laravel Valet the `php-fpm.conf` file will be located in the `/usr/local/etc/php/YOUR-PHP-VERSION` directory.

```
env[PATH] = /usr/local/bin:/usr/bin:/bin

```

This will instruct PHP FPM to look for the `gs` binary in the right places.

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](.github/LICENSE.md) for more information.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 67.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

825d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1835343?v=4)[Bob van de Vijver](/maintainers/bobvandevijver)[@bobvandevijver](https://github.com/bobvandevijver)

![](https://avatars.githubusercontent.com/u/3901745?v=4)[Tobias Feijten](/maintainers/tobias-93)[@tobias-93](https://github.com/tobias-93)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (114 commits)")[![AdrianMrn](https://avatars.githubusercontent.com/u/12762044?v=4)](https://github.com/AdrianMrn "AdrianMrn (8 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (6 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (6 commits)")[![patinthehat](https://avatars.githubusercontent.com/u/5508707?v=4)](https://github.com/patinthehat "patinthehat (4 commits)")[![tobias-93](https://avatars.githubusercontent.com/u/3901745?v=4)](https://github.com/tobias-93 "tobias-93 (3 commits)")[![Nielsvanpach](https://avatars.githubusercontent.com/u/10651054?v=4)](https://github.com/Nielsvanpach "Nielsvanpach (3 commits)")[![ntaylor-86](https://avatars.githubusercontent.com/u/28693782?v=4)](https://github.com/ntaylor-86 "ntaylor-86 (2 commits)")[![rubenvanassche](https://avatars.githubusercontent.com/u/619804?v=4)](https://github.com/rubenvanassche "rubenvanassche (2 commits)")[![akoepcke](https://avatars.githubusercontent.com/u/5311185?v=4)](https://github.com/akoepcke "akoepcke (2 commits)")[![miclf](https://avatars.githubusercontent.com/u/3188746?v=4)](https://github.com/miclf "miclf (1 commits)")[![Philhil](https://avatars.githubusercontent.com/u/1251902?v=4)](https://github.com/Philhil "Philhil (1 commits)")[![robert197](https://avatars.githubusercontent.com/u/10999294?v=4)](https://github.com/robert197 "robert197 (1 commits)")[![TVke](https://avatars.githubusercontent.com/u/15680337?v=4)](https://github.com/TVke "TVke (1 commits)")[![WinterSilence](https://avatars.githubusercontent.com/u/3521094?v=4)](https://github.com/WinterSilence "WinterSilence (1 commits)")[![wqj97](https://avatars.githubusercontent.com/u/18662395?v=4)](https://github.com/wqj97 "wqj97 (1 commits)")[![zaherg](https://avatars.githubusercontent.com/u/27624?v=4)](https://github.com/zaherg "zaherg (1 commits)")[![4n70w4](https://avatars.githubusercontent.com/u/38257723?v=4)](https://github.com/4n70w4 "4n70w4 (1 commits)")[![zandzpider](https://avatars.githubusercontent.com/u/321691?v=4)](https://github.com/zandzpider "zandzpider (1 commits)")[![abarta](https://avatars.githubusercontent.com/u/26660567?v=4)](https://github.com/abarta "abarta (1 commits)")

---

Tags

pdfconvertimagepdf-to-image

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/drenso-pdf-to-image/health.svg)

```
[![Health](https://phpackages.com/badges/drenso-pdf-to-image/health.svg)](https://phpackages.com/packages/drenso-pdf-to-image)
```

###  Alternatives

[spatie/browsershot

Convert a webpage to an image or pdf using headless Chrome

5.2k32.1M102](/packages/spatie-browsershot)[spatie/pdf-to-image

Convert a pdf to an image

1.4k15.2M64](/packages/spatie-pdf-to-image)[karkowg/php-mupdf

Minimal PDF to image converter using MuPDF

202.8k](/packages/karkowg-php-mupdf)[bobv/latex-bundle

Latex and pdf generator for Symfony 2

2432.7k](/packages/bobv-latex-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
