PHPackages                             qdev1000/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. [Image &amp; Media](/categories/media)
4. /
5. qdev1000/pdf-to-image

ActiveLibrary[Image &amp; Media](/categories/media)

qdev1000/pdf-to-image
=====================

Convert a pdf to an image

0936PHP

Since Dec 14Pushed 4y ago1 watchersCompare

[ Source](https://github.com/lenhatquang200/spatie-with-ghostscript)[ Packagist](https://packagist.org/packages/qdev1000/pdf-to-image)[ RSS](/packages/qdev1000-pdf-to-image/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)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)[![GitHub Workflow Status](https://camo.githubusercontent.com/e0bd117c61193809f3423dc699a1c2a44bbb209b14a80d7216a460709c8f8e28/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f7370617469652f7064662d746f2d696d6167652f72756e2d74657374733f6c6162656c3d7465737473)](https://camo.githubusercontent.com/e0bd117c61193809f3423dc699a1c2a44bbb209b14a80d7216a460709c8f8e28/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f7370617469652f7064662d746f2d696d6167652f72756e2d74657374733f6c6162656c3d7465737473)[![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.

Spatie is a webdesign agency in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/f318e46cb705ecc8adc0849710daf2524480f174d22f8a4f7feecc33246d0488/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f7064662d746f2d696d6167652e6a70673f743d31)](https://spatie.be/github-ad-click/pdf-to-image)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

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

[](#requirements)

You should have [Imagick](http://php.net/manual/en/imagick.setresolution.php) and [Ghostscript](http://www.ghostscript.com/) installed. See [issues regarding Ghostscript](#issues-regarding-ghostscript).

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

[](#installation)

The package can be installed via composer:

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

Usage
-----

[](#usage)

Converting a pdf to an image is easy.

```
$pdf = new Spatie\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('png')
    ->saveImage($pathToWhereImageShouldBeStored); //the output wil be a png, no matter what
```

You can set the quality of compression from 0 to 100:

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

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](.github/CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Postcardware
------------

[](#postcardware)

You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.

We publish all received postcards [on our company website](https://spatie.be/en/opensource/postcards).

Credits
-------

[](#credits)

- [Freek Van der Herten](https://github.com/spatie)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity27

Early-stage or recently created project

 Bus Factor1

Top contributor holds 75% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/87508b1fee5ef6ed903013cc5eb18afbb4c124e720663a20ec209541a9dbdabe?d=identicon)[qdev1000](/maintainers/qdev1000)

---

Top Contributors

[![Kennguyen3](https://avatars.githubusercontent.com/u/69205419?v=4)](https://github.com/Kennguyen3 "Kennguyen3 (3 commits)")[![lenhatquang200](https://avatars.githubusercontent.com/u/54436064?v=4)](https://github.com/lenhatquang200 "lenhatquang200 (1 commits)")

### Embed Badge

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

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

###  Alternatives

[milon/barcode

Barcode generator like Qr Code, PDF417, C39, C39+, C39E, C39E+, C93, S25, S25+, I25, I25+, C128, C128A, C128B, C128C, 2-Digits UPC-Based Extention, 5-Digits UPC-Based Extention, EAN 8, EAN 13, UPC-A, UPC-E, MSI (Variation of Plessey code)

1.5k13.3M39](/packages/milon-barcode)[bkwld/croppa

Image thumbnail creation through specially formatted URLs for Laravel

510496.0k23](/packages/bkwld-croppa)[char0n/ffmpeg-php

PHP wrapper for FFmpeg application

495225.1k1](/packages/char0n-ffmpeg-php)[goat1000/svggraph

Generates SVG graphs

132849.6k3](/packages/goat1000-svggraph)[cohensive/embed

Media Embed (for Laravel or as a standalone).

120370.4k](/packages/cohensive-embed)[netresearch/rte-ckeditor-image

Image support in CKEditor for the TYPO3 ecosystem - by Netresearch

63991.3k4](/packages/netresearch-rte-ckeditor-image)

PHPackages © 2026

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