Home >Backend Development >PHP Tutorial >How to Convert PDF to JPEG with High Quality and Original Size Using PHP and ImageMagick?
If you're attempting to convert a PDF file to JPEG using PHP and ImageMagick, but encountering poor quality, this article will guide you through resolving this issue. Additionally, we'll address how to maintain the original size of the PDF during conversion.
To improve the quality of the converted JPEG, you need to adjust the compression settings of the ImageMagick object. The setCompressionQuality() method accepts a value between 0 and 100, where 100 represents the highest quality. In your script, increase the value of this parameter to a higher number, such as:
<code class="php">$im->setCompressionQuality(100);</code>
To prevent the cropping of the JPEG image, you should set the resolution before loading the PDF into the ImageMagick object. Modify your script as follows:
<code class="php">// Instantiate Imagick $im = new Imagick(); $im->setResolution(300, 300); $im->readimage('document.pdf[0]'); $im->setImageFormat('jpeg'); $im->writeImage('thumb.jpg'); $im->clear(); $im->destroy();</code>
By making these adjustments, you can now convert PDF files to JPEG with both high quality and original size preservation.
The above is the detailed content of How to Convert PDF to JPEG with High Quality and Original Size Using PHP and ImageMagick?. For more information, please follow other related articles on the PHP Chinese website!