Home>Article>Backend Development> How to convert php pdf to jpg
php How to convert pdf to jpg: First create a PHP sample file; then use PHP and ImageMagick to convert PDF to JPG.
Recommendation: "PHP Video Tutorial"
The operating environment of this tutorial: Windows 7 system, PHP version 5.6, This method works for all brands of computers.
Specific question:
Convert PDF to high quality JPG using PHP and ImageMagick
I have a 300 DPI PDF that I want to convert A 300 DPI JPG at 2550x3300. I was told that ImageMagick could do this, so I got ImageMagick to work, but it only returns a JPG about 1/5 the size of the original PDF.
It's not the source image - I've done it with several high quality PDFs and they all had the same problem.
After looking for ideas on StackOverflow, this is the approach I want to use:
$im = new imagick($srcimg); $im->setImageResolution(2550,3300); $im->setImageFormat('jpeg'); $im->setImageCompression(imagick::COMPRESSION_JPEG); $im->setImageCompressionQuality(100); $im->writeImage($targetimg); $im->clear(); $im->destroy();
But this still doesn't work.
I've also tried using$ img-> resizeImage()
to resize the JPG, but if it's the right size, it's of poor quality.
Implementation method:
This is the correct method and the quality will improve.
$im = new imagick(); $im->setResolution(300, 300); $im->readImage($srcimg); $im->setImageFormat('jpeg'); $im->setImageCompression(imagick::COMPRESSION_JPEG); $im->setImageCompressionQuality(100); $im->writeImage($targetimg); $im->clear(); $im->destroy();
The above is the detailed content of How to convert php pdf to jpg. For more information, please follow other related articles on the PHP Chinese website!