nguyenhiep/pdf2image

Allow you cropping an image from file pdf

dev-master 2019-12-06 05:11 UTC

This package is auto-updated.

Last update: 2024-05-06 15:27:56 UTC


README

This package provides an easy to work with class to cropping an image from pdf file

Requirements

You should have Imagick and Ghostscript installed. See issues regarding Ghostscript.

Installation

The package can be installed via composer:

composer require nguyenhiep/pdf2image:dev-master

Usage

use Nguyenhiep\Pdf2image\Pdf2image;

$instance = new Pdf2image();

$instance->cropImage($pdf,$page,$width, $height, $startX, $startY);

the output will be saved in public/images.

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.

Security

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

License

MIT