How to convert php pdf to jpg

藏色散人
Release: 2023-03-07 19:34:02
Original
2382 people have browsed it

php How to convert pdf to jpg: First create a PHP sample file; then use PHP and ImageMagick to convert PDF to JPG.

How to convert php 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();
Copy after login

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();
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!