What are the best practices for handling image printing functionality on a website to ensure compatibility with different printer settings and paper sizes?

When handling image printing functionality on a website, it is important to ensure compatibility with different printer settings and paper sizes. One way to achieve this is by providing users with options to adjust the print settings such as paper size, orientation, and margins. Additionally, it is recommended to use CSS media queries to style the printed page specifically for printing.

<?php
echo '<style type="text/css" media="print">
    @page {
        size: A4; /* set the default paper size to A4 */
        margin: 0; /* remove default margin */
    }
    body {
        margin: 1cm; /* set margin for the content */
    }
</style>';
?>