Reputation: 13
I have to convert pdf to image format (jpg or png) for a thesis project and was planning to install the imagick library on xampp which proved to be tricky. By the way, the php version that I currently have is PHP 7.4.3.
I based the steps in installing imagick through this link: https://ourcodeworld.com/articles/read/349/how-to-install-and-enable-the-imagick-extension-in-xampp-for-windows
Installed imageMagick (ImageMagick-7.0.10-0-Q16-x64-dll.exe
)on my Windows 10 pc (upon checking with the magick -version
and was able to display the imageMagick version installed on the pc.)
Added php_imagick.dll to xampp/php/ext which I got from PHP PECL website. 3.4.4 stable 2019-05-02 imagick-3.4.4.tgz (247.5kB) DLL
Enabled the extension on php.ini file through extension=imagick
Added the binaries which I got from PECL DEPS (IMO and CORE .dlls).
11/23/2017 3:58 PM 47633113 ImageMagick-7.0.7-11-vc15-x64.zip
Upon running phpinfo() it displayed the following items:
I decided to test the library using the 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'; ?>
but web page is blank.
I tried adding the xampp/apache/bin to PATH in Windows to fix the problem but the problem is still there. In addition, this what php intelephense (extension in vscode) produced:
Is there anyone out there who can give any advice on how to make this work?
Upvotes: 0
Views: 4071
Reputation: 5299
Why not just use Imagemagick directly? You can then create batch files with standard settings you can drop your file into. You need to install Ghostscript before Imagemagick and Imagemagick will link to it auotmatically
As long as you allowed it to set the environmental variables during install this should work as a batch file:
magick -density 400 %1 "%~n1.png"
You can add whatever you want to the line.
You could also run from the command line with:
magick -density 400 "Path\to\input.pdf" "Path\to\th_%~n1.png"
Edit to answer the comment:
I have two websites using Imagemagick directly in php with exec(). I do not use Imagik as I find Imagemagick simpler and it has more options. Imagick is supposed to be safer and a bit quicker. On a server you would use something like this:
exec("magick -density 400 \"Path\to\input.pdf\" \"Path\to\output.png\" ");
Not sure about link posting here but check out my profile
Upvotes: 1