What are the potential reasons for the decrease in quality when converting PDF to JPG using Imagick in PHP?

When converting PDF to JPG using Imagick in PHP, the decrease in quality may be due to the default compression settings used during the conversion process. To improve the quality of the output JPG image, you can adjust the compression quality parameter to a higher value.

// Path to the input PDF file
$pdfFile = 'input.pdf';

// Path to save the output JPG file
$jpgFile = 'output.jpg';

// Create a new Imagick object
$pdf = new Imagick($pdfFile);

// Set the compression quality for JPG output
$pdf->setImageFormat('jpg');
$pdf->setImageCompressionQuality(100);

// Save the converted JPG file
$pdf->writeImage($jpgFile);

// Clear resources
$pdf->clear();
$pdf->destroy();