Home >Backend Development >PHP Tutorial >How to Convert PDF to JPEG with High Quality and Preserve Original Size?
For PDF conversion, scripts using ImageMagick may produce images with poor quality. Here's a solution to enhance quality and maintain the original PDF size.
The original script:
<code class="php">$im = new imagick( 'document.pdf[ 0]' ); $im->setImageColorspace(255); $im->setResolution(300, 300); $im->setCompressionQuality(95); $im->setImageFormat('jpeg'); $im->writeImage('thumb.jpg'); $im->clear(); $im->destroy();</code>
To improve quality and maintain size:
<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 setting the resolution before loading the PDF, you preserve the original size and improve image quality. ImageMagick's built-in settings may lead to cropping and size alteration. This modified script ensures faithful conversion while maintaining high quality.
The above is the detailed content of How to Convert PDF to JPEG with High Quality and Preserve Original Size?. For more information, please follow other related articles on the PHP Chinese website!