appkita / pdftoimage
Convert PDF to Image using php
Fund package maintenance!
sponsor.app-kita.net
1.0.0
2021-06-15 04:39 UTC
Requires
- php: >=7.0
Requires (Dev)
- phpunit/phpunit: ^9.5
Suggests
- ext-fileinfo: Improves mime type detection for files
README
Pdf to image library using Imagick
Installation
- composer
composer install appkita/pdftoimage
- download Github
NEW Version 3.0 (BETA)
- add convert using ghostscript
INSTALLATION EXTENSION
-
Windows a. Ghostscript download from ghostscript add your gs bin folder to PATH Environment b. Imagick
- Check PHP Version
php -i|find "PHP Version"
- Check PHP is Thread Safety
php -i|find "Thread Safety"
- Check PHP Architecture
php -i|find "Architecture"
- Download imagick from Imagick
- Once you downloaded the correct files:
- Extract from
php_imagick-….zip
thephp_imagick.dll
file, and save it to the ext directory of your PHP installation - Extract from
ImageMagick-….zip
the DLL files located in the bin folder that start withCORE_RL
orIM_MOD_RL
, and save them to the PHP root directory(where you have php.exe)
, or to a directory in your PATH variable - Add this line to your
php.ini
file:extension=php_imagick.dll
- Restart the Apache/NGINX Windows service (if applicable)
- Extract from
- To test if the extension works, you can run this PHP code:
<?php $image = new Imagick(); $image->newImage(1, 1, new ImagickPixel('#ffffff')); $image->setImageFormat('png'); $pngData = $image->getImagesBlob(); echo strpos($pngData, "\x89PNG\r\n\x1a\n") === 0 ? 'Ok' : 'Failed';
- Check PHP Version
-
Linux
-
Ghostscript download from ghostscript
-
Imagick
- Centos
sudo yum install php-imagick php -m | grep imagick
- Debian
sudo apt-get install php-imagick php -m | grep imagick
- Centos
-
Use
$file = '<<pdf file>>'; //or $file = 'URL FILE'; //configuration $option = [ 'path' => '<<result path>>', //default empty 'format' => 'png', //set image format output 'resolution' => 'set resultion image', 'prefix'=> 'convert', //set prefix name image 'layer_method'=>Imagick::LAYERMETHOD_FLATTEN, //follow Imagick Layer Method 'colosrpace'=> null, //follow Imagick colorspace 'quality'=> null, //follow imagick result quality ]; $spesific_page = null; $convert = new \Appkita\PDFtoImage\Convert($file, $option); $result = $convert->run(); //set null if you wont //or $result = $convert->run($spesific_page); /** * Or */ $convert = new \Appkita\PDFtoImage\Convert($file); $convert->path = '<<your path>>'; $convert->format = 'jpg'; $convert->run($spesific_page); /** * Or */ $convert = new \Appkita\PDFtoImage\Convert(); $result = $convert->setFile($filepdf)->run($spesific_page, $options); // if is_string $options return $path output
- URL