<?php


$pdfFile = 'output_image.pdf';
$imageFile = 'output.jpg';


    $imagick = new Imagick();

    // Set resolution before reading the image for better quality (e.g., 300 DPI)
    $imagick->setResolution(300, 300);
    
    // Read the first page of the PDF
    $imagick->readImage($pdfFile . '[0]'); 
    
    // Set the image format
    $imagick->setImageFormat('jpeg'); 
    
    // Set compression quality (optional)
    $imagick->setImageCompressionQuality(90);

    // Write the image to a file
    $imagick->writeImage($imageFile); 
    
    // Clean up
    $imagick->clear();
    $imagick->destroy();
    
    echo "PDF converted to image successfully using Imagick!";


?>
