Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to gd #1

Merged
merged 3 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ jobs:
args: --config=.php-cs-fixer.dist.php --allow-risky=yes

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Fix styling
7 changes: 2 additions & 5 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [8.2, 8.1, 8.0, 7.4]
php: [8.3, 8.2]
dependency-version: [prefer-lowest, prefer-stable]
os: [ubuntu-latest]

Expand All @@ -27,12 +27,9 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, mysql, mysqli, pdo_mysql, bcmath, soap, intl, gd, exif, iconv, imagick
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, mysql, mysqli, pdo_mysql, bcmath, soap, intl, gd, exif, iconv
coverage: none

- name: Fix Imagick Policy
run: sudo sed -i 's/none/read|write/g' /etc/ImageMagick-6/policy.xml

- name: Install dependencies
run: composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ vendor
.php_cs.cache
.phpunit.result.cache
*.cache
.idea
composer.phar
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All notable changes to `pdf-to-image` will be documented in this file

## 3.0.0 - 2024-xx-xx
- No longer use imagick for processing, use GD instead
- Colorspace and merging of layers is no longer available
- Refactor export formats to enum
- Renaming/refactoring of methods

## 2.2.0 - 2022-03-08

Expand Down
39 changes: 8 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,25 @@
[![StyleCI](https://styleci.io/repos/38419604/shield?branch=master)](https://styleci.io/repos/38419604)
[![Total Downloads](https://img.shields.io/packagist/dt/spatie/pdf-to-image.svg?style=flat-square)](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).
tobias-93 marked this conversation as resolved.
Show resolved Hide resolved

## Support us

[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/pdf-to-image.jpg?t=1" width="419px" />](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).
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

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).
You should have [Ghostscript](http://www.ghostscript.com/) installed. See [issues regarding Ghostscript](#issues-regarding-ghostscript).

## Installation

The package can be installed via composer:
``` bash
composer require spatie/pdf-to-image
composer require drenso/pdf-to-image
```

## Usage

Converting a pdf to an image is easy.

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

Expand All @@ -56,19 +46,19 @@ $pdf->setPage(2)

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

You can set the quality of compression from 0 to 100:
You can set the quality of compression (this depends on the export format, see the GD documentation for more details):
```php
$pdf->setCompressionQuality(100); // sets the compression quality to maximum
```

You can specify the width of the resulting image:
You can specify the width to scale down the resulting image:
```php
$pdf
->width(400)
->setWidth(400)
->saveImage($pathToWhereImageShouldBeStored);
```

Expand Down Expand Up @@ -104,21 +94,8 @@ Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recen

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

## Security

If you've found a bug regarding security please mail [security@spatie.be](mailto:security@spatie.be) instead of using the issue tracker.

## 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

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

## License
Expand Down
30 changes: 21 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,50 @@
{
"name": "spatie/pdf-to-image",
"name": "drenso/pdf-to-image",
"description": "Convert a pdf to an image",
"keywords": [
"spatie",
"pdf-to-image",
"pdf",
"convert",
"image"
],
"homepage": "https://github.com/spatie/pdf-to-image",
"homepage": "https://github.com/drenso/pdf-to-image",
"license": "MIT",
"authors": [
{
"name": "Freek Van der Herten",
"email": "freek@spatie.be",
"homepage": "https://spatie.be",
"role": "Developer"
"homepage": "https://spatie.be"
},
{
"name": "Tobias Feijten",
"email": "tobias@drenso.nl",
"homepage": "https://drenso.nl"
},
{
"name": "Bob van de Vijver",
"email": "bob@drenso.nl",
"homepage": "https://drenso.nl"
}
],
"require": {
"php" : "^7.2|^8.0",
"ext-imagick" : "*"
"php": ">=8.2",
"ext-gd": "*",
"ext-random": "*",
"symfony/filesystem": "^5.4 || ^6.4 || ^7.0",
"symfony/finder": "^5.4 || ^6.4 || ^7.0",
"symfony/process": "^5.4 || ^6.4 || ^7.0"
},
"require-dev": {
"pestphp/pest": "^1.21"
},
"autoload": {
"psr-4": {
"Spatie\\PdfToImage\\": "src"
"Drenso\\PdfToImage\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Spatie\\PdfToImage\\Test\\": "tests"
"Drenso\\PdfToImage\\Test\\": "tests"
}
},
"scripts": {
Expand Down
38 changes: 38 additions & 0 deletions src/Enum/ExportFormatEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Drenso\PdfToImage\Enum;

use GdImage;

enum ExportFormatEnum
{
case JPG;
case PNG;
case JPEG;

public function getExtension(): string
{
return match ($this) {
self::JPG => '.jpg',
self::PNG => '.png',
self::JPEG => '.jpeg',
};
}

public static function fromFileName(string $fileName): ExportFormatEnum
{
return match (pathinfo($fileName, PATHINFO_EXTENSION)) {
'png' => ExportFormatEnum::PNG,
'jpeg' => ExportFormatEnum::JPEG,
default => ExportFormatEnum::JPG,
};
}

public function export(GdImage $image, string $fileName, int $quality = -1): bool
{
return match ($this) {
self::JPG, self::JPEG => imagejpeg($image, $fileName, $quality),
self::PNG => imagepng($image, $fileName, $quality),
};
}
}
9 changes: 0 additions & 9 deletions src/Exceptions/InvalidFormat.php

This file was deleted.

9 changes: 0 additions & 9 deletions src/Exceptions/InvalidLayerMethod.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Exceptions/PageDoesNotExist.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Spatie\PdfToImage\Exceptions;
namespace Drenso\PdfToImage\Exceptions;

use Exception;

Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/PdfDoesNotExist.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Spatie\PdfToImage\Exceptions;
namespace Drenso\PdfToImage\Exceptions;

use Exception;

Expand Down
Loading