Pdf to image library using Imagick
Installation
- composer
composer install appkita/pdftoimage
- download Github
- add convert using ghostscript
-
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
-
$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